The output of the following program with var keyword?

No.of Views1993
Bookmarked0
By RRaveen  On 10 Feb 2011
emailbookmarkadd commentsprint
 

Code

var data = "name";
data = 8;
Console.WriteLine(data);

Options

  1. output is 8
  2. its does not compile

Answer:

Its does not compile(option 2).

var keyword is implicit type, so once you are declared  as a specific type, then it  has decide the type automatically with right hand side value.so it won't compile. 

 
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popular Interview Questions On CSharp
^ Scroll to Top