Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im having a method in a school class. and Im intanciating that class in a student class and calling that method from this class. It worked before but not working now. instead it says" it does not have a definition for the method in the school class where the method is originally from. Could you help me out please? is it something to do with the reference or .dll or something like that
Posted

It's going to depend on quite a few things: it could be any one of them.
First, I assume that the school class and the student class are both in the same project? If not, then it is a relatively simple problem.

Why would you instantiate a school from a student? A school would logically exist independently of the particular student, because it would have many students - rather than a student having many schools.

When you instantiate the school, you are presumably using the instance to access the method (or you wouldn't have mentioned it):
C#
School s = new School ();
Console.WriteLine(s.GetName());
There are two things to check here, both related to the method definition:
1) Is the method declared as public? If it isn't, and Student isn't derived from School, then you cannot access it from outside.
2) Is the method declared as static? If it is, then you can't access it from the instance, you have to use the class name instead:
C#
Console.WriteLine(School.GetName());
 
Share this answer
 
Comments
Uday P.Singh 3-Nov-11 14:30pm    
good explanation 5+
Looks like the dll reference is there - the class seems to be getting intiantiated.
Make sure your method had the appropriate access modifier.
 
Share this answer
 

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