Just looking for some opinions here... which do you like better and why? Thanks in advance!
public struct Foo
{
public readonly int Number;
public Foo(int number)
{
Number = number;
}
}
public struct Bar
{
public static readonly Foo[] AllFoos;
static Bar()
{
List<Foo> list = new List<Foo>();
for(int i=0; i< 20; i++)
{
list.Add(new Foo(i));
}
AllFoos = list.ToArray();
}
public static Foo FindFoo(int number)
{
foreach(Foo foo in AllFoos)
{
if(foo.Number == number)
{
return foo;
}
}
throw new ArgumentException(String.Format("Foo with an number of {0} not found", number), "number");
}
}
OR
public class Foo
{
public readonly int Number;
public Foo(int number)
{
Number = number;
}
}
public struct Bar
{
public static readonly Foo[] AllFoos;
static Bar()
{
List<Foo> list = new List<Foo>();
for(int i=0; i< 20; i++)
{
list.Add(new Foo(i));
}
AllFoos = list.ToArray();
}
public static Foo FindFoo(int number)
{
foreach(Foo foo in AllFoos)
{
if(foo.Number == number)
{
return foo;
}
}
return null;
}
}
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.