I was trying to learn explicit conversion in c#.
First I explicitly converted string
to int
namespace MyfirstCSharpCode
{
class Program
{
static void Main(string[] args)
{
string str = "1234";
int i = Convert.ToInt16(str);
Console.WriteLine(i);
}
}
}
it worked and the result is : 1234
Now I tried to convert char
to int
namespace MyfirstCSharpCode
{
class Program
{
static void Main(string[] args)
{
char str = '1';
int i = Convert.ToInt16(str);
Console.WriteLine(i);
}
}
}
And now the result is 49
, the ASCII value of 1
. How to get the char 1
instead of ASCII value. Please don't be too harsh its my first day in c# ;)..