开发者

how to convert char to int in java for android

开发者 https://www.devze.com 2023-04-05 03:11 出处:网络
how to convert char to int in java for android for example: int MyInt; char MyChar = \'A\'; how to insert the value 65 into MyInt?

how to convert char to int in java for android

for example:

int MyInt;
char MyChar = 'A';

how to insert the value 65 into MyInt ?

in C# it like:开发者_C百科 MyInt = Convert.ToChar(MyChar);

thanks


You can do it the same way in both C# and Java:

char myChar = 'A';
int myInt = myChar;

I wouldn't use Convert.ToInt32 (which is what I assume you meant) in C#... I'd just use the implicit conversion shown above.

EDIT: In Java, this uses the implicit widening primitive conversion specified in section 5.1.2 of the Java Language Specification:

The following 19 specific conversions on primitive types are called the widening primitive conversions:

  • byte to short, int, long, float, or double
  • short to int, long, float, or double
  • char to int, long, float, or double
  • [...]
0

精彩评论

暂无评论...
验证码 换一张
取 消