1-Simple C# Program



To write in the simple C # program, you need to understand some basic elements. They are part of almost all C # programs. You must understand these elements to do programming in C #.




The simple C program consists of the following elements.

1. Class
2. Namespaces
3. Main method ()
4. Console class and method Console.WriteLine

There are also other elements in this simple C # program, but we will discuss them in more detail later. Until then, write this code and observe the magic.




What is class?

C # is an object-oriented language. What does that mean? It means that everything has to be written in a class. The class helps you define a type that is used to represent a thing or a concept in a program.

What is Namespace?

Each class that you believe must have a unique name. In large applications where there are tons of classes that include third-party classes: naming each class differently is a daunting task. To avoid naming conflicts and organizing your code well, we have namespace. Namespace organizes your classes and other code in your application and helps give unique names that do not conflict.

For example, in this simple program, we have console class. This class is available in the System Namespace. To use the console class in your program, you must include the system namespace. That's why we have
using the system; on top. This tells the compiler to include the classes available in the System Namespace.

What is the main method ()?

Main is a special method that designates the entry point for your application. In general, there is only one Main () method to start your application. You can have multiple Main () methods but then you must specify which one should be used to start the application. Having multiple principals is a very rare scenario.

What is Console Class and Console.WriteLine?

The console class is part of the .NET Framework classes. It is available in the System Namespace. This class is used to interact with the console window. Console.WriteLine is used to write something in the console. Console.WriteLine ("Welcome to ALL FOR EASY CODE"); This line prints Welcome to ALL FOR EASY CODE in the console window.

NOTE

If you press Start in Visual Studio (press F5), the console window will disappear before viewing the output. Press Ctrl + F5 to run the program or add Console.Read () after the Console.WriteLine statement to see the console window in the previous program. I have added the line in the code to see the output on the screen.

0 comments:

Post a Comment