Thread: Chapter 34 Ex.2
View Single Post
  #1 (permalink)  
Old April 2nd, 2013, 08:47 PM
Mech_1000 Mech_1000 is offline
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 34 Ex.2


I didn't have problems working on this program and understand most of what is happening - however I had a question about where some data goes.

Section of Code:
//Parse the values
string item = fields[0];
decimal unitPrice = decimal.Parse(fields[1], NumberStyles.Any);
int quantity = int.Parse(fields[2], NumberStyles.Any);
decimal totalPrice = decimal.Parse(fields[3], NumberStyles.Any);
//Try to add a 5th field, might break data
decimal rndPrice = decimal.Parse(fields[4], NumberStyles.Any);

//Display on gridView (Takes the variables defined above and creates an object with those values.
object[] values =
rndPrice.ToString("C") //5th Field


I changed the text documents to have a 5th field (decimal number). The object values[] now holds 5 pieces of data. I add the data to the row and expected an error (out of bounds or undefined cell).

My questions are (sorry trying to keep it simple)
What happened the the fifth field in (object)values when it was added to the valuesDataGrid.Rows? Did it enter some sort of memory loss, can the value be recovered without using (object)values[4]? Or does C# do something else like automatically clean up the mistake and disregard it, which could be a problem if the user needed all the values. Lastly if this does result in some sort of memory loss would the 'using' statement w/ IDisposable be of any use in this case?