Click to See Complete Forum and Search --> : Requesting Stock numbers


johnboy14
October 30th, 2008, 04:19 PM
I want to write a program that asks for a stocknumber and when it gets my stock number it will bring up the name of the product, can I do this in a console application, any tips folks. I was planning on creating a separate class.

cilu
October 31st, 2008, 02:18 AM
Yes, you could write this in a console. And you could probably have several separate classes.

Were do you want to get the data? Some hard-coded structure? Some file on disk?

johnboy14
October 31st, 2008, 08:34 AM
can I not call the data from a class, I was comptiplating taking it from a file on my computer but I want to try taking it from a class.

MNovy
October 31st, 2008, 08:40 AM
Hi,

there is just a simple way:

- Create a new class which loads the data from any file
and stores into some internal public members, like strings, ints and so one

- Create an instance of this class in your main and call your class' method to
load the data and access the data immediately through this class. This works
if the class members are public.

Few would suggest do have get/set stuff, but I don't like them much ;-)

johnboy14
October 31st, 2008, 08:44 AM
Hi,

there is just a simple way:

- Create a new class which loads the data from any file
and stores into some internal public members, like strings, ints and so one

- Create an instance of this class in your main and call your class' method to
load the data and access the data immediately through this class. This works
if the class members are public.

Few would suggest do have get/set stuff, but I don't like them much ;-)

any examples on loading the data from any file

foamy
October 31st, 2008, 09:04 AM
any examples on loading the data from any file
Take a look at the FileStream (http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx) and StreamReader (http://msdn.microsoft.com/en-us/library/system.io.streamreader(VS.80).aspx) classes

johnboy14
October 31st, 2008, 09:41 AM
can you read from any file type, word, excel or notepad. Would it be easier to write all the current information in one class for the others to read from. I don't quite understand those classes above.

What I want is to give the stocknumber and then get the name of the product off the list, I can only think of identifying them through a class at the moment.

TheCPUWizard
October 31st, 2008, 10:20 AM
Few would suggest do have get/set stuff, but I don't like them much ;-)

Exposing (data) Fields directly is a bad practice. If places hard limits on the ability to implement techniques such as agressive/lazy evaluation. Additionally if you later have to change a field to a property, you run the risk of breaking existing code.

Unless you have (the very very rare condition) of having measured a property to introduce overhead that violdates a documented performance specification, there is NO reason to ever have data as anything other than private.

Also remember that with the latest versions of C#, you can use properties with anonymous backing fields, so there is even less reason.

johnboy14
October 31st, 2008, 10:28 AM
What about the DataSet Feature in visual c#.

ifdef
November 3rd, 2008, 12:49 PM
What about the DataSet Feature in visual c#.
This is my suggestion as well.

The DataTable Class allows you to crate a table that could represent you data and has a functions for saving it as an XML file and populating it from a previously saved XML table. It even has functions to search the table.

This seems like it is exactly what you are looking for.

TheCPUWizard
November 3rd, 2008, 01:18 PM
This is my suggestion as well.

The DataTable Class allows you to crate a table that could represent you data and has a functions for saving it as an XML file and populating it from a previously saved XML table. It even has functions to search the table.

This seems like it is exactly what you are looking for.

A DAtaSEt would certainly be a "quick and easy" solution, but it may be "heavy" (especially is DataTable.Select("...") is used!!!!!).

An alternative would be LINQ to XML....