is there any way to simplify this code into a few lines, I have a class with string seq(number) has {get;set} functions. I am getting lucio and textValue from another class.
public static void setCategorySeq(string lucio, string textValue)
{
if (lucio == "0") { seq0 = textValue; }
else if (lucio == "1") { seq1 = textValue; }
else if (lucio == "2") { seq2 = textValue; }
else if (lucio == "3") { seq3 = textValue; }
else if (lucio == "4") { seq4 = textValue; }
else if (lucio == "5") { seq5 = textValue; }
else if (lucio == "6") { seq6 = textValue; }
else if (lucio == "7") { seq7 = textValue; }
else if (lucio == "8") { seq8 = textValue; }
else if (lucio == "9") { seq9 = textValue; }
else if (lucio == "10") { seq10 = textValue; }
else if (lucio == "11") { seq11 = textValue; }
else if (lucio == "12") { seq12 = textValue; }
else if (lucio == "13") { seq13 = textValue; }
else if (lucio == "14") { seq14 = textValue; }
else if (lucio == "15") { seq15 = textValue; }
}
Maybe this code will suit you:
static Dictionary<string, string> seq = new Dictionary<string, string>(); public static void setCategorySeq(string lucio, string textValue) { seq[lucio] = textValue; } public static string setCategorySeq(string lucio) { if (seq.ContainsKey(lucio)) return seq[lucio]; return null; }
May be this could help you reducing the LOC.
Just use a dictionary
then to set an entry in the dictionary
and to access it
if you really want to verify that the string is a value between 0 an 15 then parse it first and validate it and use a dictionary with integer as a key
I hope this might help