Few things:
1.) Regarding your actual question , you have two options:
You can iterate over a field Bar(or a property if you change it to a property as indicated below) in your code:
Foo foo = new Foo();
foreach(Bar bar in foo.Bar)
{
...
}
Or you can do Fooimplement IEnumerable<Bar>(this is harder):
public class Foo : IEnumerable<Bar>
{
.. your existing code goes here
public IEnumerator<Bar> GetEnumerator()
{
return Bar.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return Bar.GetEnumerator();
}
}
This will allow you to do this:
Foo foo = new Foo();
foreach(Bar bar in foo)
{
}
. , Foo ( ) Bar, .
2.) , , - , . :
public class Foo
{
public string Something
{
get { return ...; }
set { ... = value; }
}
}
, . - :
public class Foo
{
private string something;
public string Something
{
get
{
return something;
}
set
{
something = value;
}
}
}
, , get, - set ( , ).
-, ( ), , , . ( / - ) , , . # 3.0 auto, :
public class Foo
{
public string Something { get; set; }
}
Something , . # ( get, set ) .