Prime number is a number which is divisible by itself or 1, so we will apply logic to get number by user. Now, the last line of code " Console.WriteLine("Hello World") ", this line basically, prints 'hello world' on the console, Console.WriteLine is method in "System" namespace which is used here and "Hello World" is passed as a string argument inside this method. String args= argument passed to method, which is string array, which is used to store the command line arguments. Main = method name,this method is the entry-point of our application, that is, the first piece of code to be executed, and in our example, the only method to be executed. Void = return type of method, means this method will return anything, some methods can return data-type like int, string etc., but as this method returns nothing so "void" is used. Static = this is another keyword in C#, here static defines that this class method, can be called without needing of the object ( you will learn more about Class/Object in Here ), basically we create objects of class and then call methods inside the class using those objects created by us, but as this method is defined as "static", it doesn't need to called using Class Object. Public = again, access modifier of C#, public means it is can be accessed publicly from anywhere in the application. Now, let's understand next line of code " public static void Main(string args)", i will explain keywords and it's meaning one by one. Program = name of the console application, which can be anything. ![]() Public = access modifier in C#, means this class can be accessed publicly from anywhere in the application. In this case, the class is simply called Program. Now, next line of code is " public class program", as C# is an Object Oriented language, every line of code that actually does something, is wrapped inside a class. If you have created program in Visual Studio you will see one extra line " namespace ConsoleApp1", basically this is the namespace of this Class " Program" In the above code, we have imported a namespace " System", using is a keyword, highlighted with blue by the editor, by 'using' keyword, we import Class or namespace. Here is the simple C# code to print Hello World using System In Visual Studio, if you have downloaded Visual Studio Community version, you can open "File"-> "New"-> "Project", then Select "Console Application" ( Search "Console" in top-right, if you cannot find it), name it "Hello World" and click "OK" You can consider working on Visual Studio IDE, but i will be using online IDE ( dotnetfiddle), so you can play with the code, if needed. Let's start with basic C# program which is printing "hello world" in console application in C#. C# program to search an element in an array Hello world program in c#.Printing right angle triangle pattern using * in C#.Check if int is palindrome or not in C#.If you have just started learning to program in C# or you are a beginner student who is willing to learn C#, here are the few basic C# sample programs with output and explanation which will help beginner and student to learn C# more easily.
0 Comments
Leave a Reply. |