I just collected some knowledge regarding and it seems to be very little to understand following scenario.
I have 2 classes. One has Main method and other has two Extension Methods as follow.
Class having Main
class Program { static void Main(string[] args) { string uuu = "214"; Console.WriteLine(uuu.SplitMe().AddMe()); Console.ReadKey(); } } Extension Class
static class ExtensionClass { public static char[] SplitMe(this string value) { return value.ToCharArray(); } public static long AddMe(this char[] value) { int sum = 0; for (int i = 0; i<value.Length ; i++) { sum += Convert.ToInt32(value[i]); } return sum; } } I was expecting, in following line
Console.WriteLine(uuu.SplitMe().AddMe()); output of uuu.SplitMe() to be char[] of {'2','1','4'} and result of complete line to be printed as 7 (2+1+4) but it is 151 on my console. Could you please elaborate how its being calculated?
Thanks.
Int32.ParseinsteadInt32.Parse.