Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I create one class name PersonalInfo.CS. i want to call this class to another class like EmplInfoc.cs
Posted

you need to create an instance of PersonalInfo in your EmplInfoc you do that by using the new keyword. E.g.
C#
PersonalInfo personalInfo = new PersonalInfo();
personalInfo.APublicMethod();


This is very basic however, so I don't feel you will get satisfying answers here as explaining the basics takes a bit more then a few lines of explanation. I suggest you go to a bookstore and find yourself a book.
 
Share this answer
 
I suppose both the classes defined in the same project.
You may freely call public static members of PersonalInfo.
You may call public members of it if you have an object of type PersonalInfo (i.e. an instance of the PersonalInfo class).
 
Share this answer
 
The class name is PersonalInfo. It resides in a file with the name PersonalInfo.cs, at least I hope so.

As an addition to what is already said: If one of your classes is derived from the other (as person and employee suggest, but I could be totally wrong on that), you could use protected variables and methods of the parent class from within the child class.
 
Share this answer
 
You can create an instance of PersonalInfo inside EmplInfoc.

class EmplInfoC
{
   PersonalInfo o = new PersonalInfo();
}
 
Share this answer
 
v2
create instance for the class you want use thats it
 
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