Hi everyone,
I recently started to learn C# and picked up the excellent Head First C# book. One thing I noticed that the book teaches is that the keyword NEW is used to created an instance of a class. I would like to know if you need to use the NEW keyword or if you can't simply create a class, say Example, and then just call Example EX1, instead of doing Example EX1=new Example?
Thanks for any clarification on this
Loading
DonPosted Oct 13, 2008, 2:05 PM
As I remember from C++, you could just create a class and then to create an instance of that class, if the class was called student, wouldn't you just do this: student Jake, student Tom, etc?
Daniel Innala AhlmarkPosted Oct 12, 2008, 2:28 PM
or shorter:
Example ex = new Example();
Kirtan PatelPosted Oct 12, 2008, 1:40 AM
You have to declare the method Static in Order to use it direct without making Class Instance
Here I have Created Employee Class and in the Employee Class Having Method "printEmployeeName()" and declared it as Static method
Now i call this method from main Function Without making Instance of class
public class Test
{
public static void Main()
{
Employee.printEmployeeName();
Console.ReadLine();
}
}
class Employee
{
public static void printEmployeeName()
{
Console.Write("Emp Name is Kirtan");
}
}
Thanks ,
Hope It Will be helpful to you :-)
Happy Coding :-)