Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to declare user defined Nullable type in C#
WhatsApp
Rajan Singh
Jun 24
2015
1.1
k
0
0
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
Up Next
How to declare user defined Nullable type in C#