LINQ to OBJECT(HashTable)

Scenario:

A detail class(Marks), which contains Object of a Structure(MarkDetails) as Data Member. There are some member functions like AddorUpdateRecord which is use to update data.
Another class named "MarksInfo" containing HashTable. The HashTable contains the object of class "Marks" as value fields and some key, (Hashtable will have one entry per student).

Requirement: We need to make DataTable that contains marks of all the students.



Code:
public struct MarksDetails
{  public Int32 RollNo;  public Int32 Hindi;  public Int32 English;  public Int32 Maths;
};
public class Marks
{
  MarksDetails markDetails;   public Marks()       {
       markDetails = new MarksDetails();         // other required part       }   public Int16 AddOrUpdateMarks()
        {
          /*Code to Add or Update marks*/
        }
  public MarksDetails GetMarksDetails()
        {
             return markDetails; 
        }
} public class MarksInfo {     private HashTable m_hashTable;     public MarksInfo()     {       /*Code for Constructor*/     }     public void AddOrUpdateHashTable(string Key, Marks marks)     {      /*Code to Update HashTable*/     }     // Other Reuqired Member functions     public DataTable GetStudentMarksTable()     {       DataTable l_dTblStuMarks = new DataTable();       DataColumn l_dcRoll = new DataColumn("RollNo");       DataColumn l_dcHindi = new DataColumn("Hindi");       DataColumn l_dcEnglish = new DataColumn("English");       DataColumn l_dcMaths = new DataColumn("Maths");             l_dTblStuMarks.Columns.Add(l_dcRoll);       l_dTblStuMarks.Columns.Add(l_dcHindi);       l_dTblStuMarks.Columns.Add(l_dcEnglish);       l_dTblStuMarks.Columns.Add(l_dcMaths);      var l_ds = (from hashEntry in m_hashTable.Cast<DictionaryEntry>()                 let marksValues = ((Marks)hashEntry.Value).GetMarksDetails()                 select l_dTblStuMarks.LoadDataRow(new object[]{                                                  marksValues.RollNo,                                                  marksValues.Hindi,
                                                 marksValues.English,
                                                 marksValues.Maths,},false));                  long recordCount = l_ds.LongCount();                  return l_dTblStuMarks;     } }

No comments:

Post a Comment