The title may be incorrect, if so please change. I'm not sure how to ask my question so just look at the code as it should be obvious.
Using the commented code will work but I want to know why the actual code does not work. I'm sure it's wrong but how can it be fixed? Or is this not how its done?
using System;
namespace SomethingAwful.TestCases.Structs
{
public class Program
{
public static void Main()
{
Foo f = new Foo();
f.Bar.Baz = 1;
Console.WriteLine(f.Bar.Baz);
}
}
public class Foo
{
public struct FooBar
{
private int baz;
public int Baz
{
get
{
return baz;
}
set
{
baz = value;
}
}
public FooBar(int baz)
{
this.baz = baz;
}
}
private FooBar bar;
public FooBar Bar
{
get
{
return bar;
}
set
{
bar = value;
}
}
//public FooBar Bar;
public Foo()
{
this.bar = new FooBar();
//this.Bar = new FooBar();
}
}
}