No, the compiler takes care of creating a private field for that purpose in
that case, so it is not accessible to us for modifications. That was
probably a mistake on my part for not interpreting the code Miguel posted
correctly. I figured he might have omitted unnecessary getter/setter code
for his post.
--
Stanimir Stoyanov
http://stoyanoff.info
"Family Tree Mike" <(E-Mail Removed)> wrote in
message news:05906494-A10A-478A-9BAE-(E-Mail Removed)...
> You cannot put it inline in an automatic property, can you?
>
> "Stanimir Stoyanov" wrote:
>
>> Hi Miguel,
>>
>> It appears that this.Levels (actually, the field that is used in the
>> Levels
>> property) is not initialized. Instantiate it as new List<Level>() in
>> either
>> your constructor before the this.Levels.Add() call or inline beside the
>> declaration.
>> --
>> Stanimir Stoyanov
>> http://stoyanoff.info
>>
>> "shapper" <(E-Mail Removed)> wrote in message
>> news:de7831c8-9af3-4869-90a2-(E-Mail Removed)...
>> > Hello,
>> >
>> > I have a class as follows:
>> >
>> > public class Theme {
>> >
>> > public Subject Subject { get; set; }
>> > public List<Level> Levels { get; set; }
>> > public string Note { get; set; }
>> >
>> > public Theme() {
>> > this.Levels.Add(new Level { Type = LevelType.Basico,
>> > Description = "Test" });
>> > }
>> >
>> > Level is a class with two properties:
>> > - Type (of type LevelType which is an Enum)
>> > - Description which is a string
>> >
>> > I am getting an error:
>> > Object reference not set to an instance of an object.
>> >
>> > What am I doing wrong?
>> >
>> > Probably this is something simple but I have been around this and I
>> > can't figure out what I am doing wrong.
>> >
>> > Thanks,
>> > Miguel
>> >
>>
>>