T
Tony Johansson
Hello!
Here is the class Category and both methods is this class are instance
methods.
I just wonder I could change and use static methods and fields instead so
is there any best practice when it's adviceable
to use static method.?
class Category
{
private NameValueCollection nvc = new NameValueCollection();
public Category()
{
Init();
}
/// <summary>
/// This method initialize the <key,value> pair collection where key
is category and value is animalType
/// </summary>
private void Init()
{
nvc.Add(CategoryType.Mammal.ToString(), AnimalType.Cat.ToString());
nvc.Add(CategoryType.Mammal.ToString(), AnimalType.Dog.ToString());
nvc.Add(CategoryType.Mammal.ToString(),
AnimalType.Horse.ToString());
//nvc.Add(CategoryType.Bird.ToString(), "Duck");
//nvc.Add(CategoryType.Bird.ToString(), "Kolibri");
//nvc.Add(CategoryType.Insect.ToString(), "Butterfly");
//nvc.Add(CategoryType.Insect.ToString(), "Bee");
//nvc.Add(CategoryType.Marine.ToString(), "Pike");
//nvc.Add(CategoryType.Marine.ToString(), "GoldFish");
//nvc.Add(CategoryType.Reptile.ToString(), "Frog");
//nvc.Add(CategoryType.Reptile.ToString(), "Snake");
}
/// <summary>
/// This method return the values for the corresponding passed key
/// </summary>
/// <param name="key"></param>
/// <returns> An Ilist as string array</string></returns>
public IList<string> GetMyValues(string key)
{
List<string> returnValueList = new List<string>();
foreach (string s in nvc.GetValues(key))
{
returnValueList.Add(s);
}
return returnValueList.AsReadOnly();
}
}
//Tony
Here is the class Category and both methods is this class are instance
methods.
I just wonder I could change and use static methods and fields instead so
is there any best practice when it's adviceable
to use static method.?
class Category
{
private NameValueCollection nvc = new NameValueCollection();
public Category()
{
Init();
}
/// <summary>
/// This method initialize the <key,value> pair collection where key
is category and value is animalType
/// </summary>
private void Init()
{
nvc.Add(CategoryType.Mammal.ToString(), AnimalType.Cat.ToString());
nvc.Add(CategoryType.Mammal.ToString(), AnimalType.Dog.ToString());
nvc.Add(CategoryType.Mammal.ToString(),
AnimalType.Horse.ToString());
//nvc.Add(CategoryType.Bird.ToString(), "Duck");
//nvc.Add(CategoryType.Bird.ToString(), "Kolibri");
//nvc.Add(CategoryType.Insect.ToString(), "Butterfly");
//nvc.Add(CategoryType.Insect.ToString(), "Bee");
//nvc.Add(CategoryType.Marine.ToString(), "Pike");
//nvc.Add(CategoryType.Marine.ToString(), "GoldFish");
//nvc.Add(CategoryType.Reptile.ToString(), "Frog");
//nvc.Add(CategoryType.Reptile.ToString(), "Snake");
}
/// <summary>
/// This method return the values for the corresponding passed key
/// </summary>
/// <param name="key"></param>
/// <returns> An Ilist as string array</string></returns>
public IList<string> GetMyValues(string key)
{
List<string> returnValueList = new List<string>();
foreach (string s in nvc.GetValues(key))
{
returnValueList.Add(s);
}
return returnValueList.AsReadOnly();
}
}
//Tony