How to add values to a collection object in c#?
I am trying to add list of values which are in the incremental sequence to a collection object.
Sample syntax :-
Source Data
FirstName LastName Department Salary
-------------------------------------------------------
John Boone Developer 100
Albert Post Manager 500
Benjamin Nayyar Developer 100
public class MyGroup
{
public int RowIndex { get; set; } // Row Index
public int ColumnIndex { get; set; } // Column Index
public object ColumnValue { get; set; } // Column Value
}
class A
{
List<MyGroup> objMyGrp = new List<MyGroup>();
int iGrpCount = 0;
objMyGrp[iGrpCount].RowIndex = excelCell.RowIndex;
objMyGrp[iGrpCount].ColumnIndex = excelCell.ColumnIndex;
objMyGrp[iGrpCount].ColumnValue = excelCell.Value.ToString();
}
iGrpCount++;
Expected output :-
RowIndex ColumnIndex ColumnValue
1 1 John
1 2 Boone
1 3 Developer
1 4 100
2 1 Albert
2 2 Post
2 3 Manager
2 4 500
3 1 Benjamin
3 2 Nayyar
3 3 Developer
3 4 100
Error :- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Expected Result :
Object objMGrp is a collection object which will store the Row Index Number, Column Index Number and Column value in the incremental sequence. I will have to use that object for sorting and validating the values.