TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to declare user defined Nullable type in C#
Rajan Singh
Jun 24
2015
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System.IO;
using
System;
struct
MyStruct
// Declare a struct.
{
public
int
X;
// Field
public
int
Y;
// Field
public
MyStruct(
int
xVal,
int
yVal)
// Constructor
{
X = xVal;
Y = yVal;
}
}
class
NullableType
{
static
void
Main(
string
[] args)
{
MyStruct mSStruct =
new
MyStruct(6, 11);
// Variable of struct
MyStruct ? mSNull =
new
MyStruct(5, 10);
// Variable of nullable type
Console.WriteLine(
"mSStruct.X: {0}"
, mSStruct.X);
Console.WriteLine(
"mSStruct.Y: {0}"
, mSStruct.Y);
Console.WriteLine(
"mSNull.X: {0}"
, mSNull.Value.X);
Console.WriteLine(
"mSNull.Y: {0}"
, mSNull.Value.Y);
}
}
Output:
mSStruct.X: 6
mSStruct.Y: 11
mSNull.X: 5
mSNull.Y: 10
User Defined Nullable Type