![]() |
|
#1
|
||||
|
||||
Classes in C#Hello,
i'm taking my very first C# class, and i think i need to help. It's a very simple project. I'm supposed to get book information from a form and add it into a class array. So far i have my Book and Library Classes. this is my ADD Button. C-SHARP / C# Code:
the error that i'm getting is: Error 1 'HW2.Library' is a 'type' but is used like a 'variable' C:\School\CMIS398\HW2\Main.cs 48 13 HW2 i don't understand what it means.. please help. this thing is, our teacher gave us a working program to go by, and i though i did a pretty good job incorporating it into my own, but i keep getting this error. here is the code he gave us for his ADD button: C-SHARP / C# Code:
EDIT: i'v decided to add my 2 classes here too, just in case. C-SHARP / C# Code:
LIBRARY C-SHARP / C# Code:
__________________
Xrum! |
|
#2
|
||||
|
||||
Re: Classes in C#Hi, Kacyndra.
Just like in C++, classes need to be instantiated in order to be used - you must create an object. So, in order to use the Library class, you have to do something like: C-SHARP / C# Code:
Now, I see the intent of the classes you shown is not really to have an array of Libraries, but rather one container Library class holding all the books (you can of course create more Libraries if need be). So, why not use the Add member function of the Library class to add Books to it? Remember we instantiated the Library to hold up to 20 books, so instead of: C-SHARP / C# Code:
do C-SHARP / C# Code:
I have not tested the code, but this is the logic that most appeals to me. If you can't get it to work, I'll further look into it. Kind regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
||||
|
||||
Re: Classes in C#Quote:
Also, I see you have an indexer for returning books: C-SHARP / C# Code:
But you do not have one for adding books, because there is no set component - only get. If you will add one (see my little tutorial for reference), you will be able to use the indexer instead of the Load method: C-SHARP / C# Code:
Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assistance with classes... | Bravebird | C++ Forum | 7 | 27-Apr-2005 13:17 |
| bug w/ templated classes | f15e | MS Visual C++ / MFC Forum | 4 | 06-Mar-2005 23:56 |
| Fairly simple classes help please | sammacs | C++ Forum | 0 | 30-Nov-2004 09:58 |
| First time using classes | crystalattice | C++ Forum | 6 | 13-Oct-2004 08:21 |
| using windows WMI and CMI classes in Dev-c++ | Dawis | C++ Forum | 0 | 26-Oct-2003 04:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The