Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I have a class - Performance.
Made of Fields - Acadamics, Physic, Socials.

C#
class Performance
{
    public string Acadamic {get; set;}
    public string Physical {get; set;}
    public string Socials {get; set;}
}


On my Form:
Performance p = new Performance();
String s = p.Acadamics;

Its perfect but I want to include Exams, CA, Semesters, etc, as sub Fields or parameters to proceed to:

p.Acadamics.CA.Semester;
or even further.
How do I go about it please?
Thank you.
Posted
Updated 1-Jan-15 4:54am
v3
Comments
BillWoodruff 1-Jan-15 7:43am    
To think clearly about OO design in this case, we need to know what you are going to be storing in instances of the 'Performance Class; for example: is each instance going to hold data for one student ? one instance hold data for an entire class of students, or some group of students you selected based on some criteria ?
George Jonsson 2-Jan-15 1:02am    
Instead of presenting the code first, you should in this case clearly describe the problem and then show the code.
Maybe by defining the problem in text or in a diagram you will actually see the solution yourself.
Salisu Shaibu 5-Jan-15 10:07am    
So sory to have left you to dance in the dark for long Bill.
Something happened and I could not follow up with solutions to my propblem.
The fact is, I'm working on individual students.
Trying to compute performances within semesters or accadamic sessions.
Being it accadamic, Physical, Social, Religous, etc.
While each feild or property could have two or more items to deal with in the manner examplified above.
Hope you understand, thank you.

Hello Salisu,
The Exams, CA & Semesters can't be called parameters, they would rather be the properties of another set of class.

Like in a heirarchy.
FOr instance,
Performance is the main class that would contain List of Academics, List of Physics, List of Socials.
Then Academics would be another class with the properties required like CA and Exams may be. Then only you can invoke the properties in heirarchy as you have mentioned in your query.
I hope you understand what I say, if my anticipation was correct on your query.
Please post back your queries if any.
Thanks
 
Share this answer
 
Comments
BillWoodruff 1-Jan-15 8:38am    
I don't see why they couldn't be parameters. However, until the OP clarifies what they are doing now, and what they want to achieve, we are "dancing in the dark."
[no name] 1-Jan-15 9:58am    
You are correct Bill. We are dancing in the dark...banghead.. :)
BillWoodruff 1-Jan-15 10:30am    
Well, perhaps it's better to dance in the dark so the elephant who is trying to find the wise man has less of a chance of stepping on us ? :) Happy New Year !

p.s. Elephants are, to me, "sacred beings," and it disturbs me greatly that the word "elephant" is now used as a curse, insult, or as scatological term, by some.
[no name] 1-Jan-15 10:35am    
ha ha ..:D
Happy new Year Bill... have a great year ahead. :)
First thing is programming is always to make a good sketch of your system, for which you're going to write the application for, or atleast the logic for.

In your case, which seems more like an institute's system to save the student's overall performance. In that case, you should move importantly focus on the student himself and these other classes must not be of string data type but of their own class's data type. Such as this one,

C#
class Performance
{
    public Academic Academic {get; set;}
    public Physical Physical {get; set;}
    public Socials Socials {get; set;}
}


.. now to make them work, you must have corresponding classes for them to control the data being passed, like this maybe,

C#
class Academic {
   public string static Course {get; set}
   public string static Semester {get; set;}
   // other properties here
}


You can build other two classes, (Physical and Socials) like above one that would hold their own data in them. In this way, you can define the classes and objects to contain the related data in them. Now, you would know that when you're going to call the properties, you would be able to call them like,

C#
Performance performance = new Performance();
performance.Academic.Course; // because Course is a static field


But it won't let you access the Semester field, because there will be an error saying, "string" doesn't contain any definition of "Semester". That is legit, because Semester is not a property or member of System.String[^] or string.

I really would like to recommend that you first of all, start to learn how to use the C# language, and what are objects and how to call these properties from the code. Then you will be able to understand these features and might be able to create a long query by each member returning an object that would allow the next member to be called and so on and so forth.

One more thing, I did notice that there was an ambiguity in your identifiers for members being called and inside the class. You should not use any typos while writing the names, C# is a case-sensitive and letter-sensitive language. Names of the identifiers and members must match in order to compile as it is, the source code won't even compile.

Good luck!
 
Share this answer
 
v2
Comments
BillWoodruff 1-Jan-15 15:28pm    
I think you are off-track in using 'static variables here; while we are pretty much in the dark about exactly what they OP wants, I think it's safe to assume there will be multiple instances of whatever the class-design is, and each instance will need its own Academic, etc. fields, properties, or structs, or whatever.
Afzaal Ahmad Zeeshan 1-Jan-15 15:41pm    
Actually what I wanted to show him was how to create a long thread that he wanted to create. Which required some static members to be called.

Yes Bill, you're right! We are all in dark because this question, atleast for me, seems like OP didn't have any idea and came here to ask for "A good class project based on this system" kind of question.

Right, each object must have their own class, as I did mention in my answer, that every object must not be thrown out as a string, int or any other. But instead they must have their own properties, their members etc. Instances would be different, but for each of the student, his fields would not change so, static. I think only the performance, or if any super-class Student, is present, it must be instantiated, then other classes for that student must be static, directly call-able without having to create instance for each of the property or member etc. Like, Academic ac = new Academic(student); by passing the student as a parameter.

.. or should they? :-)
BillWoodruff 1-Jan-15 21:10pm    
fyi: I did not down-vote your solution. I would tell you if I did.
Afzaal Ahmad Zeeshan 2-Jan-15 1:15am    
No Bill, that is not a problem. :-)

As always my request to down-voter would still be to let me know where do I lack in my answer.
Salisu Shaibu 5-Jan-15 12:03pm    
Ya Afzaal Ahmad.
Thanks for the assumtions about me and my problem.
I truely don't know much about Objects but curiosity was my drive.
Your respond is indeed a blessing.
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900