I have the following string, which I split and store into a List of strings. Afterwards when I'm going to use these elements, I am getting an error of "Indexoutofrange" but how is this possible ?
the string:
"getName():String
getTitle():String
getStaffNo():Int
getRoom():String
getPhone()"
my code:
List<myObject> myObjectList = new List<myObject>();
// in valueList Im now storing the string input and also split them at the whitespaces
List<string> valueList = System.Text.RegularExpressions.Regex.Split(stringValue, @"\s{2,}").ToList<string>();
foreach (string stringValue in valueList)
{
// in tmp variable I'm splitting the stored string at ':' because the left side of the split is the name of the object und the right side is the type
var tmp = stringValue.Split(':');
myObject object1 = new myObject()
{
object1.name = tmp[0];
object1.type = tmp[1];
};
myObjectList.Add(object1);
}
After I just run my unit Test Im getting all object.name right, so "getName", "getTitle", "getStaffNo", "getRoom" and "getPhone" are correctly stored in each object but the type refers to an error => "IndexOutOfRangeException". I just can't explain the exception because there should be at tmp[1] the value "String" stored
Can someone help me out please?