Let me consider this statement from the question Chemical.ChemicalName[IndexNumber]
, We can consider Chemical
as a class or as an object of some other class. If it is a class means the ChemicalName
will be a static.
Then comes the ChemicalName
definitely it will be a collection(List/Array or something like that) or even an object of a class which having an indexer
.
Case 1: consider Chemical
is class and ChemicalName
is a List of string So the Definition will be :
public class Chemical
{
public static List<string> ChemicalNames = new List<string>(){"name1","name 2"};
}
So that you can access a single name like the following:
string someChemicalName=Chemical.ChemicalNames[0]; // will be name1
Case 2: consider Chemical
is an object of a class and ChemicalName
is a List of string So the Definition will be :
public class Chemicals
{
public List<string> ChemicalNames;
}
Then you can access create the Chemical
by using the following code:
Chemicals Chemical= new Chemicals();
Chemical.ChemicalNames=new List<string>(){"name1","name 2"};
Here also you can workout your statement like this
string someChemicalName=Chemical.ChemicalNames[0]; // will be name1