Method extension for safely type convert(outcoldman.ru)
submitted by
outcoldman(100) 2 years, 2 months ago
Recently I read good Russian post with many interesting extensions methods after then I remembered that I too have one good extension method “Safely type convert”. Idea of this method:
int i;
i = "1".To<int>();
// i == 1
i = "1a".To<int>();
// i == 0 (default value of int)
i = "1a".To(10);
// i == 10 (set as default value 10)
i = "1".To(10);
// i == 1
|category: C#
|Views: 6
tags:
C# another
Everyones tags:
Your Tags: