I am new to c# with that in mind can some one please tell me how to call a class file that i have created in to a windows form file.for example how do i call a function that handles error logs to call and run on a form file. I hope u understand what i am trying to say.

8 Years
Discussion Span
Last Post by saravind84

If you have created the class in the same project you just instantiate it the same way you do other classes:

//if you created a class called MyClass with a method called DoStuff
//then you would call it like this:

MyClass class = new MyClass(); //create instance of class
class.DoStuff(); //call method of class
Votes + Comments
very helpful

Also make sure that the "windows form file Class" and the "MyClass" are in the same Namespace. Otherwise you need to qualify the class name with the Namespace. Suppose the namespace for the MyClass is NewNameSpace, then use the code below.(Modified the code posted above)

NewNameSpace.MyClass class = new NewNameSpace.MyClass(); //create instance of class
class.DoStuff(); //call method of class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.