C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

Mention the two major categories that distinctly classify the variables of C# programs?

0 votes
31 views
asked Feb 24, 2014 by sara Guru (24,570 points)

1 Answer

0 votes
 
Best answer
Variables that are defined in a C# program belong to two major categories: value type and reference type. The variables that are based on value type contain a value that is either allocated on a stack or allocated in-line in a structure. The variables that are based on reference types store the memory address of a variable, which in turn stores the value and are allocated on the heap. The variables that are based on value types have their own copy of data and therefore operations done on one variable do not affect other variables. The reference-type variables reflect the changes made in the referring variables.
 
Predict the output of the following code segment: 
 
int x = 42; 
int y = 12;
int w;
object o;
o = x;
w = y * (int)o; 
Console.WriteLine(w);
 
/* The output of the code is 504. */
 
answered Feb 24, 2014 by sara Guru (24,570 points)

Related questions

0 votes
1 answer 2,023 views
0 votes
1 answer 20 views
0 votes
1 answer 59 views
59 views asked Feb 24, 2014 by john Guru (27,140 points)
0 votes
1 answer 22 views
22 views asked Jan 20, 2014 by sara Guru (24,570 points)
0 votes
1 answer 383 views
383 views asked Nov 16, 2011 by shivani Sr Member (1,090 points)
...