Puzzle on Byte values addition Gives Different output in C# and VB.Net

Hello Friends !
Greetings


I will show an puzzle which display different output in VB.Net and C#.Think on it.

class Program
{
public static void main()
{
byte a = 100;
byte b = 200;
byte c= a + b;

Console.Writeline(c);
Console.ReadLine();
}
}

Now what output it will display when compile this application
it gives you compile Time Error like that
Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)


BUT BUT When u do the same code in VB.Net
then it gives you RunTime Error."Arithmetic operation resulted in an overflow."

And Interesting thing is that when you change value of a from 100 to 1 and b from 200 to 2.It will run successfully and display 3....in VB.Net.

So Conclusion of Above Puzzle is that
Type Casting Aspect is strongly used and recommend in C#.Developers need to take care of it

Whereas

in VB.Net (Considering Option strict off), it will do internally Type Casting.


Suggest Me if you find any other difference in VB.Net and C#


Thanks
Shubhank Upadhyay

Comments

Popular posts from this blog

Difference Between ArrayList and Generic.List C#/VB.Net

String Function in SQL-Substring,Reverse,CharIndex

Cloud and How I cleared AZ-900 Microsoft Azure Fundamental exam and Why I choose fundamental