Meaning? operator in C # for properties

Possible duplicate:
? (nullable) in c #

In System.Windows.Media.Animation, I see the code as follows:

public double? By { get; set; } 

What is he doing? is the operator here? Somebody knows?

I tried to use this on Google, but it’s hard to find a carrier if you don’t know what it was called by name. I checked the page on the operators ( http://msdn.microsoft.com/en-us/library/6a71f45d (v = vs .80). Aspx ), but? the operator is not specified there.

Thanks!

+7
source share
7 answers

? is a decorator. T? is the same as Nullable<T> , i.e. value type with a null value.

The documentation for the By property explains why it is used here:

The property controls the progress of A DoubleAnimation ; but instead of setting the By property, you can also set the From and To properties (or either) to control the progress of the animation. Any combination of properties (except To and By ) is allowed, so there should be a way to report that the property is not set - therefore, its value is zero.

Use the By property if you want to animate the value "by" a certain amount, instead of specifying a start or end value. You can also use the By property with the From property.

+18
source

What? means that it is zero (the value can be set to null.

Nullable Types (C # Programming Guide)

+6
source

This is not an operator. Rather, it is a special abbreviated syntax for declaring values ​​with a null value .

+2
source

This property is null, it means you can set By = null , without ? you get an error that cannot be null

+1
source

? means Nullable types, it means By in your case to store a null value, which is not possible for a value type

+1
source

This means that the type is null.

See this page for more details.

+1
source

it is syntactic sugar processed by the C # compiler.

Does this mainly refer to the "double"? like Nullable, which allows null. It basically wraps a double value inside another object.

+1
source

All Articles