If I need to get info from a database, items from an invoice, for instance… should I just get the data into a data table, and store them into variables, or should I create a class?
What’s better?
MyClass.ItemNumber;
MyClass.Price;
MyClass.InvoiceNumber;
or…
myItemNumber = (int)dt["itemnumber"];
myPrice = (double)dt["price"];
myInvNum = dt["InvNum"].ToString();
Why? If it’s something I will never have to use anywhere else, are variables fine, or is it beneficial to create a “Invoice Class”? If I get data, store it in a class instance, is it cached for form posts in .Net? Or is each page recreating the class instance/db call, etc.? How about performance? Please explain concepts. The concepts are the hardest thing for me to grasp… coding–easy. Concepts of .Net–not so easy.
If its for immediate use only, class is definitely an unneeded overhead.
Your datatable dt is already an entity in the memory with the data. Variables are enough.