I think strong typing is gonna drive me nuts
I have a string, say MyString = "12345" and I want to convert the second character to an int. I VB it was easy: val(mid(MyString,2,1)) = 2
In C# its somewhat tougher, since I can't convert a string OR a char[] to an integer.
These don't work:
int i = MyString.Substring(2,1);
int i =MyString.ToCharArray(2,1);
Nor can I cast my way out of this:
int i = (char)MyString.Substring(2,1);
int i =(char)MyString.ToCharArray(2,1);
Am I missing something obvious, or have I simply butted heads with strong typing? What's the most elegant solution out of this? Overloading the string class?
I have a string, say MyString = "12345" and I want to convert the second character to an int. I VB it was easy: val(mid(MyString,2,1)) = 2
In C# its somewhat tougher, since I can't convert a string OR a char[] to an integer.
These don't work:
int i = MyString.Substring(2,1);
int i =MyString.ToCharArray(2,1);
Nor can I cast my way out of this:
int i = (char)MyString.Substring(2,1);
int i =(char)MyString.ToCharArray(2,1);
Am I missing something obvious, or have I simply butted heads with strong typing? What's the most elegant solution out of this? Overloading the string class?