can we assign null value to value type in c#?
Answers were Sorted based on User's Feedback
Answer / neelima
string is a reference type..its not a value type..
| Is This Answer Correct ? | 61 Yes | 8 No |
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 |
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 |
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 |
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 |
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 |
Why to use “using” in c#?
Why interface is required?
What are the types of delegates in c#?
What is dataset and dataadapter in c#?
What is the difference between overriding and overloading in systemverilog?
What exception can an overridden method throw in comparison with the method it is overriding?
What is the use of tryparse in c#?
What is the difference between array and list in c#?
What is the use of console readkey in c#?
One start and stop button is there and one textbox is there.when you click start button ,it will display 1,2,3......up to infinite in textbox.when you click stop button it will stop.
Is string nullable in c#?
Is 0 an unsigned integer?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)