Results 1 to 6 of 6

Thread: Type Casting Issue

Threaded View

  1. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Type Casting Issue

    i am still little confuse.why we write short inside the small braket (short).Can someone tell me why this happens? Clarify Please.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace CastingDemo
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
               Int16 a= 10;
               Int32  b= 20;
               Int16 c;
               c = (short)(a + b);
               MessageBox.Show(c.ToString());
                
            }
        }
    }
    additional why this following code is not working ???.
    Code:
    private void Form1_Load(object sender, EventArgs e)
            {
               Int16 a= 10;
               Int32  b= 20;
               Int32  c;
               c = (long)(a + b);
               MessageBox.Show(c.ToString());
             }
    Last edited by firoz.raj; Jul 19th, 2010 at 03:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width