Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A curious C# syntax with a question mark

Tags:

private enum E_Week {    Mon = 0,    Tue,    . . . } 

What does the following code mean?

E_Week? week= null; 

Is it equal to the following code? What is the function of the '?' sign here?

E_Week week= null; 
like image 983
Carlos Liu Avatar asked Jan 15 '10 06:01

Carlos Liu


People also ask

Whats does curious mean?

curious • \KYUR-ee-us\ • adjective. 1 a : marked by desire to investigate and learn b : marked by inquisitive interest in others' concerns : nosy 2 : exciting attention as strange, novel, or unexpected : odd. Examples: She has a curious habit of mumbling to herself constantly while she does her crossword puzzles. "

What is a word for a curious person?

inquisitive, nosy. (or nosey), prying, snoopy.

What is the verb of curious?

Verbs frequently used with curiosity. arouse someone's curiosity: arouse, awaken, excite, fuel, pique, provoke, rouse, spark, stimulate, stir, whetWhen Roland starts sending Cherry coded messages, her curiosity is aroused.

Is Curiousness a word?

Curiousness definitionInquisitiveness; curiosity. (dated) The state of being curious; exactness of workmanship; ingenuity of contrivance.


1 Answers

Your code is using what's called a nullable type. An enum, much like an int or a DateTime, is what is known as a "value type", which is required to always have some value. Nullable types allow you to treat value types as if they do allow null values.

For example, this code is invalid and won't compile because enums cannot be null:

E_Week week = null; 

But this code is valid:

E_Week? week = null; 

And it's exactly the same as this:

Nullable<E_Week> week = null; 
like image 163
Eilon Avatar answered Sep 18 '22 12:09

Eilon