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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bijayani Baijayanti
NA
14
0
Using NULL-COALESCE Operator in C#
Jun 8 2010 7:32 AM
Hi,
I am sharing a tips on "Using NULL-COALESCE Operator in C#".
To my knowledge perhaps the least used operator in C# is the null-coalescing operator .
But you can use it effectively to reduce the lines of code you write .
The null-coalesce operator can be used to define / return a default value for a nullable value type / reference type and this is represented by two consecutive question marks (??).
Here is how you can use it :
Ex. 1 : Assign default value to Value type
// define a nullable int
int? x = null;
// assign a value to another integer, but check if it contains null value
// if a null is there, assign a default value
int y = x ?? -1;
Hope you find this
tips
useful and of assistance.
Thanks,
Bijayani
Reply
Answers (
1
)
Problem Looping controls using Parallel.foreach
probelm in displaying animated progress bar