» Integer summing blues, short += short problem
Integer summing blues, short += short problem
|December 3, 2010
Posted by forumadmin
Program in C#:
short a, b;
a = 10;
b = 10;
a = a + b; // Error : Cannot implicitly convert type 'int' to 'short'.
// we can also write this code by using Arithmetic Assignment Operator as given below
a += b; // But this is running successfully, why?
More Related Questions
- Can I convert long to int? I want to convert long to int.
If the value of long > int.MaxValue, I am happy to let it wrap around.
What is the best way? Asked By - […]
- Why can I pass 1 as a short, but not the int variable i? Why does the first and second Write work but not the last? Is there a way I can allow all 3 of them and detect if it was 1, (int)1 or i passed in? And really why is one allowed but the […]
- Strings and ints, implicit and explicit Had a coworker ask me this, and in my brain befuddled state I didn't have an answer:
Why is it that you can do:
string ham = "ham " + 4;
string ham = 4;
If there's an […]
- How do I convert a decimal to an int in C#? How do I convert a decimal to an int? Asked By - Neil P Read Answers
- In C#, how do I check if a type is a subtype OR the type of an object? To check if a type is a subclass of another type in C#, it's easy:
typeof (SubClass).IsSubclassOf(typeof (BaseClass)); // returns true
However, this will fail:
- Objective-C : BOOL vs bool I'm new to Objective-C and I saw the "new type" BOOL (YES, NO).
I read that this type is almost like a char.
For testing I did :
NSLog(@"Size of BOOL %d", sizeof(BOOL));
NSLog(@"Size of […]
- Extending System.Convert System.Convert has a really useful utility for converting datatypes from one type to another. In my project, I have many custom types. I want to convert command line arguments to these […]
- Best Way to get Whole Number part of a Decimal Number What is the best way to return the whole number part of a decimal (in c#)? (This has to work for very large numbers that may not fit into an int).
GetIntPart(343564564.4342) >> […]
- Why do I have to assign a value to an int in C# when defaults to 0? This works:
int b = a;
But this gives a compiler error ("Use of unassigned local variable 'a'"):
- C# char to int So I have a char in c#:
char foo = '2';
Now I want to get the 2 into an int. I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2. The […]