Some understanding regarding Extension Methods

c#, extension-methods

Solution

The issue is that a `System.Char` value of `'2'` has an integer value of 50, not 2. As such, you're summing `{'2','1','4'}`, which have values of `{50, 49, 52}`, which in turn becomes 151.

You could convert the characters to numbers matching their value via:

sum += int.Parse(value[i].ToString());

However, this will raise an exception if you pass a string that contains non-numeric characters.

Problem

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.

Original source