[dba-VB] C# serialization

jwcolby jwcolby at colbyconsulting.com
Tue Oct 13 11:13:13 CDT 2009


 > Of course, I can see an educational purpose by handcrafting a kind of database, but ...

LOL.  Well, this is after a CLASS in C# the purpose of which is to LEARN C#.  You do not start at 
typed data sets, you start with "this is a variable" and "this is a for loop".  I am very much at 
that level.

I am quite sure that in a year I will be throwing out typed datasets with the best of them but right 
now I am still forgetting to put a ; at the end of the line.

Have patience Master #2.

John W. Colby
www.ColbyConsulting.com


Gustav Brock wrote:
> Hi John
> 
> Sounds like a quite normal database app to me ...
> 
> If so, all the typed dataset stuff is ready at your hands.
> To persist (to an XML file without the overhead you claim about) use method WriteXml.
> To read it at load, use method ReadXml. Can't be simpler.
> 
> Of course, I can see an educational purpose by handcrafting a kind of database, but ...
> 
> /gustav
> 
> 
>>>> jwcolby at colbyconsulting.com 13-10-2009 17:37 >>>
>  >Do these classes inherit typed datasets?
> 
> Nope, no connection to a database.
> 
> The original assignment was to build a grade calculator where you simply input a list of grades. 
> There are three types of grades, each with a different weight (Tests - 40% of grade, Labs - 50% of 
> grade and DL 10% of grade).
> 
> There is no requirement to do anything more than the above, calculating a total count of each grade 
> type, sum of each type, average of each type and weighted average of each type, and then the same 
> calculations for the totals.
> 
> In order not to be bored to death, and with the approval of the instructor, I expanded the 
> assignment to include using classes and collections.  I store each grade in an instance of clsGrade. 
>   I store all of each TYPE of grade in an instance of clsGrades (plural) which contains a generic 
> collection into which the instances of clsGrade are inserted.  This collection is strongly typed so 
> that it can only accept clsGrade objects.
> 
> Each instance of clsGrades (plural) is inserted into a sorted list in clsCalculator, keyed on 
> GradeType (keyed on the string "Test", "Lab" or "DL").  In the main form there is a combo with three 
> grade type strings ("Test", "Lab" and "DL") which when selected is passed in to clsCalculator which 
> indexes into the collection to access the correct instance of clsGrades.  Adding new grades, 
> deleting grades and updating existing grades is all done on the selected instance of clsGrades.
> 
> So...
> 
> clsCalculator - interfaces to the form and has a sorted collection holding three instances of...
> clsGrades - contains a strongly typed generic collection holding multiple instances of ...
> clsGrade - contains each grade.
> 
> clsGrades performs the calculations to count (collection.count), sum, average and weighted average 
> all of the grades contained within.
> 
> clsCalculator requests the various computed values from the three instances of clsGrades and 
> performs the calculations to create an overall Count (sum of clsGrades.Count), Sum (sum of 
> clsGrades.Sum), Average, weighted sum etc.
> 
> Now...
> 
> I want to write the grades in each clsGrades instance to a single file, then read it back in again. 
>   Persist the grades to disk.  I have no requirement to persist the data to disk, I simply want to 
> do so.
> 
> Please please please do not suggest a "better way" for doing the assignment, it is all written and 
> functions exactly as you would expect it to work.  You may of course enlighten me on different 
> options, but I will not be rewriting the core assignment at this point.
> 
> This was just a homework assignment and it is in fact finished.  If I can persist it great, if not 
> that's OK too.  I have learned a lot and thought I might learn how to do the persist thing, streams, 
> serialization (if that is used) etc.  Even classes and collections are a "next semester" thing so I 
> am ahead of the curve at this point.
> 
> John W. Colby
> www.ColbyConsulting.com 
> 
> 
> Charlotte Foust wrote:
>> John,
>>
>> I'm not sure I understand what you're doing.  Do these classes inherit
>> typed datasets?  If so, the parent class can easily return a child class
>> that already contains a typed dataset of child records.  You don't
>> actually need collections for that.  In that case, grade wouldn't need
>> to be a class (although it could be, I just don't see any need).  The 
>>
>> Charlotte Foust 
> 
> 
> 
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
> 
> 



More information about the dba-VB mailing list