Nullable class

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

Hello,

Is it so that a class can't be Nullable?
E.g. following code dosn't compile.
Have I understand Nullable classes wrong or is the syntax wrong?

Cheers,

- John
public class MyWay

{

private string myString;

public string MyString

{

get { return myString; }

set { myString = value; }

}

}

class Program

{

private Nullable<MyWay> myWay = null;

public void CallMyWay()

{

if (myWay.HasValue)

{

Console.WriteLine(MyString);

}

else

{

Console.WriteLine("MyWay is null");

}

}

static void Main(string[] args)

{

new Program().CallMyWay();

}

}
 
Hello,

Is it so that a class can't be Nullable?
E.g. following code dosn't compile.
Have I understand Nullable classes wrong or is the syntax wrong?

A class is ALWAYS nullable, it was the values types that were not
nullables, hence the added Nullable type requires that the parameter
to be a valued type.
 
Hello,

Is it so that a class can't be Nullable?
E.g. following code dosn't compile.
Have I understand Nullable classes wrong or is the syntax wrong?

A class is ALWAYS nullable, it was the values types that were not
nullables, hence the added Nullable type requires that the parameter
to be a valued type.
 
Back
Top