2

I have the following piece of code, and I have no idea what the ? means in the construct.

What is it doing?

myObj_Request r = new myObj_Request(); //instantiate intial object
r.Channels = new ChannelSequence();    //initial object has another object in channels
r.Channels.ChannelType = new ChannelType?[5] { .. } // ok so we have 5 channeltypes...
                                                    // but  that ? infront of [5] ?
Alex
  • 5,674
  • 7
  • 42
  • 65

3 Answers3

2

It's a nullable type. Difference?

int c = 5; // you can set only numbers

int? d = null; // you can set int or null
int? e = 5;

int? is basically exactly equal to Nullable<int>.

Here's the reference: MSDN

[edit]

So new ChannelType?[5] is an array (5 elements) of Nullable<ChannelType>.

Nickon
  • 9,652
  • 12
  • 64
  • 119
1

Nullable type: check Link . You'll find more here.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
Andrei Neculai
  • 472
  • 2
  • 5
  • 21
0

"?" this will be used to make VeluTypes to NullableTypes

Ex:

Int is value type. You can't assign null to it. If you declare it like int?...you can assign null here

Murugavel
  • 269
  • 1
  • 2
  • 9