can we assign null value to value type in c#?

Answers were Sorted based on User's Feedback



can we assign null value to value type in c#?..

Answer / amit kumar sharma

//Use this
int? intNull = null;

Is This Answer Correct ?    64 Yes 10 No

can we assign null value to value type in c#?..

Answer / neelima

string is a reference type..its not a value type..

Is This Answer Correct ?    61 Yes 8 No

can we assign null value to value type in c#?..

Answer / anirudh

YES. WE CAN !!!


use this:

int? var_x = null;

Is This Answer Correct ?    34 Yes 4 No

can we assign null value to value type in c#?..

Answer / aditya

Nullable type is introduced in .NET 2.0. Before 2.0 it was
not possible to assign null to value types.
This was possible with the introduction of Generics in 2.0
and the it would be something like this...

System.Nullable<int> x = new System.Nullable<int>;

or

int? salary = null (new type modifier in 2.0)

Is This Answer Correct ?    30 Yes 7 No

can we assign null value to value type in c#?..

Answer / suman k dey

Use nullable type

Is This Answer Correct ?    29 Yes 9 No

can we assign null value to value type in c#?..

Answer / yogesh

Cannot convert null to a value type.
So it is not possible to assign null to value type.

Value types include:
All numeric data types
Boolean, Char, and Date
All structures, even if their members are reference types
Enumerations, since their underlying type is always
Byte, Short, Integer, or Long

Reference types include:
String
All arrays, even if their elements are value types
Class types, such as Form
Delegates

Is This Answer Correct ?    20 Yes 10 No

can we assign null value to value type in c#?..

Answer / ahmad al mursalin

Yes, In C# 2.0 there is introduced one new type called
nullable types. through this we can assign null value in any
value type like...
bool?flag=null;
but before evaluate this value we should check flag value like..
if(!flag.HasValue)
{
flag=true;
}
after that we have to cast bool value to bool like..
if((bool)flag)
{
//write your code.
}

Is This Answer Correct ?    11 Yes 3 No

can we assign null value to value type in c#?..

Answer / shihafath wazeer

correct declaration for a nullable integer is as follows

Nullable<int> i = null;

or

int? j = null;

Is This Answer Correct ?    5 Yes 1 No

can we assign null value to value type in c#?..

Answer / narayana

Yes We can Assign
A nullable int can store null. Nullable types in the C#
language can be constructed by specifying the question mark
after a value type in a declarator statement. The nullable
int can be specified with the syntax "int?".

Example:
int a=b=10;
int? c= null;
c=a+b

Is This Answer Correct ?    2 Yes 0 No

can we assign null value to value type in c#?..

Answer / jay

string a = string.Empty;
a = null;

Is This Answer Correct ?    14 Yes 20 No

Post New Answer

More C Sharp Interview Questions

What is the difference between a class and an object c#?

0 Answers  


What is the use of command builder?

0 Answers  


Define Virtual folder?

0 Answers   Arigo Infotech,


What?s a delegate?

2 Answers  


Asha buys 16 Chocolates for rs 12 and 24 chocolates for rs 20, if she sold them 30 chocolates for rs 30 then what is the Gain/Loss percentage? Gain(700/19 %) Loss(700/19 %) Gain(500/19 %) Loss(500/19 %) If one person ate 100 grapes in 5 days and 6 more each day from starting, what was the no of grapes he ate on first day? 6 8 10 7 If seven men P, Q, R, S, T, U, V parked his car, P and Q something like that. 6 student J, K, L, M, N, O went for picnic in 2 batches, K and L have to go together, M and O do't go together, if O and L go in one batch then which of these combination will be wrong. Jmnp Jklo klop JKLO a boat can go upstream and down stream, if it goes 5/2 times of downstream at the speed of 6 kmph then what will be the speed of upstream? 15 KMPH 12 KMPH 10 KMPH 11 KMPH A, B, C, D, E sitting on a table, A sits 2 seat left from B and C sits 2 seat right from B then what will not be the combination ACDE

0 Answers   Symphony,


what is webapplication? what is windows application? what is the extension for both . in what purpose we r using webapplication. in which situation we r using windowns application

1 Answers  


Why do we need delegates?

0 Answers  


What is an interface class? Give one example of it

0 Answers  


Is array reference type / value type?

15 Answers   Accenture,


Define multicast delegate in c#?

0 Answers  


Explain the difference between the system.array.copyto() and system.array.clone()?

0 Answers  


To allow an element to be accessed using a unique key which .NET collection class is used ?

0 Answers   Siebel,


Categories