Click here to Skip to main content
16,015,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i cast a character to int I am getting different value. why

C#
Console.WriteLine((int)a);
            Console.WriteLine((int)'a');

result is

97
347

why I am getting these two different results. ?
Posted
Updated 13-Dec-14 17:50pm
Comments
DamithSL 13-Dec-14 23:49pm    
what is "a" in line 1?

results are not marching with your code. char 347 is 'ś', you may have change the value of variable somewhere else.

C#
using System;

public class Test
{
    public static void Main()
    {
        var a ='a';
        Console.WriteLine((int)a);
            Console.WriteLine((int)'a');
    }
}


result :
VB
97
97

DEMO[^]
 
Share this answer
 
v2
Comments
ksiyadkk 14-Dec-14 0:05am    
ya, I am really sorry. it was my mistake. I already set a variable on top. Thanks for your answer.
Because they're different things?

In the first statement a is a variable, please use Improve question to show us what type it is and what value you set it to.

In the second statement you are looking at a literal character 'a'. I don't know why it is reporting 347, it should be 97, I suspect you are misrepresenting the situation.
 
Share this answer
 
v3
Comments
ksiyadkk 14-Dec-14 0:05am    
ya, I am really sorry. it was my mistake. I already set a variable on top. Thanks for your answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900