I have written a function to populate values into a class whose structure is as given below
public class Country
{
public string Name { get; set; }
public string Continent { get; set; }
public string Zone { get; set; }
public India IndiaInfo { get; set; }
}
public class India
{
public List<State> StateInfo{get; set;}
}
public class State
{
public string StateName { get; set; }
public string StateCode { get; set; }
}
The values are populated into the class object as shown below
public void PopulateCountry(string name, string Asia , string GMT , string AbcState, string RichState)
{
Country objCountry = new Country();
objCountry.Continent = Asia;
objCountry.Name = name;
objCountry.Zone = GMT;
**India objIndia = new India();
objIndia.StateInfo = new List<State>;
State objState = new State();
objState.StateCode = AbcState;
objState.StateName = RichState;
objIndia.StateInfo.Add(objState);
objCountry.IndiaInfo = objIndia;**
}
In the above method to populate the object of class Country I have taken a brute force approach and put the values in the class and the code is giving results too. However this code is not following some of the best practices and can be further enhanced /rewritten especially the one in Bold. Can someone point out the things/features/practices of C# I am missing.
Edit# 1 Magus pointed out some of the conventions i was not following Regarding this particular method, PopulateCountry 1) can we have better methods to instantiate the state object/india object , taking into account their relationship as per class structure 2) the last line of code where i have directly assigned the object,is that fine and according to standards?