Click here to Skip to main content
15,897,273 members
Home / Discussions / C#
   

C#

 
AnswerRe: Error message- Expected class delegate,enum,interface or struct Pin
Gareth H20-May-08 14:26
Gareth H20-May-08 14:26 
AnswerDid nobody spot the obvious? Pin
Anthony Mushrow20-May-08 14:34
professionalAnthony Mushrow20-May-08 14:34 
GeneralRe: Did nobody spot the obvious? Pin
Angelinna20-May-08 14:55
Angelinna20-May-08 14:55 
GeneralRe: Did nobody spot the obvious? Pin
Anthony Mushrow20-May-08 15:10
professionalAnthony Mushrow20-May-08 15:10 
QuestionRe: Did nobody spot the obvious? [modified] Pin
Angelinna20-May-08 15:49
Angelinna20-May-08 15:49 
AnswerRe: Did nobody spot the obvious? Pin
Christian Graus20-May-08 18:00
protectorChristian Graus20-May-08 18:00 
AnswerRe: Error message- Expected class delegate,enum,interface or struct Pin
Nouman Bhatti20-May-08 21:46
Nouman Bhatti20-May-08 21:46 
AnswerRe: Error message- Expected class delegate,enum,interface or struct Pin
DaveyM6921-May-08 0:11
professionalDaveyM6921-May-08 0:11 
I think you're a bit confused on classes here - you need to do some serious research and study.

I'll try to help a little but I'm not doing it for you - I'm sure you wouldn't want me to!

Let's look at a Pupil class.
There's many ways to create a class, but I find the easiest is to have four sections (or regions - you can actually use this word in your code!).
1. Member variables - declare these as private so only the class itself can modify them.
2. Properties - public so they can be accessed outside of the class.

One benifit of the above two over a single public variable is the property get and set methods can alter/filter/validate the data. There a many others but this isn't supposed to be an article!

3. Methods - these actually do stuff with the data and if necessary return a value of any type needed.
4. Constructors - these are used to create an instance of your class.

This is an example Pupil class - see if you can follow what's happening. When you understand *EVERY* line you may be ready to attempt the task you've posted. This code won't work fully without some work and understanding from you as it references 2 other classes - Homework and PupilHomework. I'm leaving it up to you to create those, make them interact with the Pupil class, and add any neccesary enhancements to the Pupil class.
public class Pupil
{
    #region Member Variables
    private int m_ID;
    private string m_Name;
    private List<PupilHomework> m_HomeworkList;
    private static int lastID = 0;
    #endregion

    #region Properties
    public int ID
    {
        get { return m_ID; }
    }
    public string Name
    {
        get { return m_Name; }
        set { m_Name = value; }
    }
    public List<PupilHomework> HomeworkList
    {
        get { return m_HomeworkList; }
    }
    #endregion

    #region Methods
    public void AddHomework(Homework homework)
    {
        m_HomeworkList.Add(new PupilHomework(homework.ID));
    }
    #endregion

    #region Constructors
    public Pupil(string name)
    {
        m_Name = name;
        m_ID = ++lastID;
        m_HomeworkList = new List<PupilHomework>();
    }
    #endregion
}


Dave

GeneralRe: Error message- Expected class delegate,enum,interface or struct Pin
Angelinna21-May-08 2:24
Angelinna21-May-08 2:24 
GeneralRe: Error message- Expected class delegate,enum,interface or struct Pin
DaveyM6921-May-08 3:22
professionalDaveyM6921-May-08 3:22 
QuestionHow Can My Program Take StartUp Arguments? Pin
That Asian Guy20-May-08 13:35
That Asian Guy20-May-08 13:35 
AnswerRe: How Can My Program Take StartUp Arguments? Pin
Gareth H20-May-08 13:52
Gareth H20-May-08 13:52 
GeneralRe: How Can My Program Take StartUp Arguments? Pin
That Asian Guy20-May-08 14:09
That Asian Guy20-May-08 14:09 
AnswerRe: How Can My Program Take StartUp Arguments? Pin
PIEBALDconsult20-May-08 14:46
mvePIEBALDconsult20-May-08 14:46 
GeneralRe: How Can My Program Take StartUp Arguments? Pin
Vikram A Punathambekar20-May-08 18:51
Vikram A Punathambekar20-May-08 18:51 
GeneralRe: How Can My Program Take StartUp Arguments? Pin
PIEBALDconsult21-May-08 13:06
mvePIEBALDconsult21-May-08 13:06 
QuestionThe directive 'servicehost' is unknown Pin
Member 391904920-May-08 9:54
Member 391904920-May-08 9:54 
AnswerRe: The directive 'servicehost' is unknown Pin
Expert Coming20-May-08 10:21
Expert Coming20-May-08 10:21 
QuestionReturn a row count Pin
mreynol520-May-08 8:56
mreynol520-May-08 8:56 
AnswerRe: Return a row count Pin
led mike20-May-08 9:10
led mike20-May-08 9:10 
AnswerRe: Return a row count Pin
Miszou20-May-08 9:21
Miszou20-May-08 9:21 
QuestionHow to invoke 'TypeConverter.CreateInstance' Pin
Lea Hayes20-May-08 8:55
Lea Hayes20-May-08 8:55 
QuestionC# and crystal report Pin
shabonaa20-May-08 8:43
shabonaa20-May-08 8:43 
AnswerRe: C# and crystal report Pin
led mike20-May-08 9:01
led mike20-May-08 9:01 
AnswerRe: C# and crystal report Pin
keyboard warrior20-May-08 9:19
keyboard warrior20-May-08 9:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.