Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My interviewer asked the below question on me that is

Create class for HelloWorld ?

and my answer was below

C#
public class fnhelloworld()
{
     MessageBox.Show("Hello World");
}

is it right ?

Regards,

Peer Mohammed.A
Posted
Updated 26-May-14 19:41pm
v2
Comments
Richard MacCutchan 27-May-14 4:10am    
Since we don't know what the interviewer wanted it's difficult to be certain. But even though you used the class keyword, you created a method, not a class.

No,try below
C#
public class fnhelloworld
{
    public fnhelloworld()
	{
          MessageBox.Show("Hello World");
	}
}


And read the Documentation first
Classes (C# Programming Guide)[^]
 
Share this answer
 
v2
it is wrong class doen't contain ()

Class can be created like this.. :)

C#
public class HelloWorld
      {
          public string HelloWorldSyntax { get; set; }

      }


here i have created HelloWorld class with HelloWorldSyntax string property.. :)

Introduction to C# classes[^]
 
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