Click here to Skip to main content
15,883,940 members
Home / Discussions / C#
   

C#

 
QuestionUsing Controls from plugin dll's Pin
Pieter Alec Myburgh29-Aug-06 3:44
Pieter Alec Myburgh29-Aug-06 3:44 
AnswerRe: Using Controls from plugin dll's Pin
Sebastian Schneider29-Aug-06 4:38
Sebastian Schneider29-Aug-06 4:38 
QuestionTransition between forms, next, back buttons Pin
Saamir29-Aug-06 3:44
Saamir29-Aug-06 3:44 
AnswerRe: Transition between forms, next, back buttons Pin
Sebastian Schneider29-Aug-06 4:33
Sebastian Schneider29-Aug-06 4:33 
GeneralRe: Transition between forms, next, back buttons Pin
Saamir29-Aug-06 5:02
Saamir29-Aug-06 5:02 
AnswerRe: Transition between forms, next, back buttons Pin
Nader Elshehabi29-Aug-06 7:32
Nader Elshehabi29-Aug-06 7:32 
QuestionRemoting with IPC Pin
ejuanpp29-Aug-06 3:34
ejuanpp29-Aug-06 3:34 
QuestionInt16 is not Int16 are you missing a cast? Pin
MY120129-Aug-06 3:27
MY120129-Aug-06 3:27 
Hello.

I've have this little method (yes - I know it makes no sense - but it is a test):

<br />
public void AddNumbers()<br />
{<br />
  Int16 a = 2;<br />
  Int16 b = 4;<br />
  Int16 c = 6;<br />
<br />
  Int16 result = a + b + c;<br />
}<br />


The above will not compile. I get the CS0266 compiler error: Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?)

But this will:
<br />
public void AddNumbers()<br />
{<br />
  Int16 a = 2;<br />
  Int16 b = 4;<br />
  Int16 c = 6;<br />
<br />
  Int32 result = a + b + c;<br />
  // or this line:<br />
//Int16 result = (Int16)(a + b + c);<br />
}<br />


Now why is this happening? I've checked the IL code for the method, it looks like this:

<br />
.method public hidebysig instance void  AddNumbers() cil managed<br />
{<br />
  // Code size       14 (0xe)<br />
  .maxstack  2<br />
  .locals init ([0] int16 a,<br />
           [1] int16 b,<br />
           [2] int16 c,<br />
           [3] int32 result)<br />
  IL_0000:  nop<br />
  IL_0001:  ldc.i4.2<br />
  IL_0002:  stloc.0<br />
  IL_0003:  ldc.i4.4<br />
  IL_0004:  stloc.1<br />
  IL_0005:  ldc.i4.6<br />
  IL_0006:  stloc.2<br />
  IL_0007:  ldloc.0<br />
  IL_0008:  ldloc.1<br />
  IL_0009:  add<br />
  IL_000a:  ldloc.2<br />
  IL_000b:  add<br />
  IL_000c:  stloc.3<br />
  IL_000d:  ret<br />
} // end of method Program::AddNumbers<br />


As far as I can see IL adds the numbers as ldc.i4. is this integer 4 byte? Because if it is, why does it not get the numbers from ldc.i2. instead? Since my variables are of the type Int16?

Can anybody tell me why?

Best regards
Soeren
AnswerRe: Int16 is not Int16 are you missing a cast? Pin
Dan Neely29-Aug-06 3:37
Dan Neely29-Aug-06 3:37 
GeneralRe: Int16 is not Int16 are you missing a cast? Pin
User 665829-Aug-06 3:52
User 665829-Aug-06 3:52 
AnswerRe: Int16 is not Int16 are you missing a cast? [modified] Pin
User 665829-Aug-06 3:46
User 665829-Aug-06 3:46 
GeneralRe: Int16 is not Int16 are you missing a cast? Pin
Dave Kreskowiak29-Aug-06 4:26
mveDave Kreskowiak29-Aug-06 4:26 
AnswerRe: Int16 is not Int16 are you missing a cast? Pin
Mike Dimmick29-Aug-06 6:46
Mike Dimmick29-Aug-06 6:46 
QuestionDeclare class as partial class in CodeDOM Pin
Ista29-Aug-06 3:23
Ista29-Aug-06 3:23 
AnswerRe: Declare class as partial class in CodeDOM Pin
Ista29-Aug-06 3:26
Ista29-Aug-06 3:26 
GeneralRe: Declare class as partial class in CodeDOM Pin
Marcos Accioly29-Aug-06 3:29
Marcos Accioly29-Aug-06 3:29 
QuestionUsing .NET's WMI to Identify Pen-Drive's Unique ID Pin
Marcos Accioly29-Aug-06 3:22
Marcos Accioly29-Aug-06 3:22 
AnswerRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
mav.northwind29-Aug-06 8:25
mav.northwind29-Aug-06 8:25 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
Marcos Accioly29-Aug-06 9:09
Marcos Accioly29-Aug-06 9:09 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
Dave Kreskowiak29-Aug-06 9:17
mveDave Kreskowiak29-Aug-06 9:17 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
mav.northwind29-Aug-06 10:24
mav.northwind29-Aug-06 10:24 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
Marcos Accioly29-Aug-06 10:29
Marcos Accioly29-Aug-06 10:29 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
mav.northwind29-Aug-06 10:35
mav.northwind29-Aug-06 10:35 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
Marcos Accioly30-Aug-06 3:48
Marcos Accioly30-Aug-06 3:48 
GeneralRe: Using .NET's WMI to Identify Pen-Drive's Unique ID Pin
mav.northwind1-Sep-06 4:11
mav.northwind1-Sep-06 4:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.