Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C Sharp only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
C Sharp
How to initalize enum to null or blank?
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
Sri13
New Member
Join Date:
Sep 2010
Posts:
11
#1
How to initalize enum to null or blank?
Dec 2 '10, 04:23 PM
Is there a way to initialize an enum to null/empty?
Code:
public enum Color { Red, Blue }
How to do something:
Color c = null;
or
Color c = "";
hype261
New Member
Join Date:
Apr 2010
Posts:
207
#2
Dec 2 '10, 07:34 PM
I believe you can create a Nullable enum like other value types. To declare a Nullable enum you just do...
Code:
Color? c = null;
Comment
Post
Cancel
GaryTexmo
Recognized Expert
Top Contributor
Join Date:
Jul 2009
Posts:
1501
#3
Dec 3 '10, 03:04 PM
I'm sure you figured it out, but to any others reading this thread, remember that you need to access the Value property of a nullable type to get its value.
Pretty easy to spot, but still sometimes throws people for a loop :)
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment