Auto-Implemented Properties and Nullable Types

  • Thread starter Thread starter Stefan Hoffmann
  • Start date Start date
S

Stefan Hoffmann

hi @all,

has anybody an explanation, why string? is not allowed for an
auto-implemented property?

namespace Test
{
class Class1
{
int? NullableInt { get; set; }
string? NullableString { get; set; }
}
}


mfG
--> stefan <--
 
hi Stefan,

Stefan said:
has anybody an explanation, why string? is not allowed for an
auto-implemented property?
Found it:

public struct Nullable<T> where T : struct


arghh
--> stefan <--
 
Because string is a reference-type (class), not a value-type (struct).

Strings can already be null - just use:

string Foo {get;set;}

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top