Advertisement

Responsive Advertisement

C#

 Introduction of C#


C# is pronounced and known as "C-Sharp".

It is an object-oriented programming language created by Microsoft that runs on the .NET Framework.

C# has roots from the C family, and the language is close to other popular languages like C++ and Java.

The first version was released in year 2002. The latest version, C# 12, was released in November 2023.

C# is used for:

  • Mobile applications
  • Desktop applications
  • Database applications
  • Web applications
  • Web services
  • Games
  • VR
  • Web sites And much, much more!
Why should we use and benefits C#?

  • It is one of the most popular programming languages in the world
  • It is easy to learn and simple to use
  • It has huge community support
  • C# is an object-oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs
  • As C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa
Installation of C# IDE

Get started with C# is to use an IDE.

An IDE (Integrated Development Environment) is used to edit and compile code.

we will use Visual Studio Community, which is free to download  https://visualstudio.microsoft.com/vs/community/.

Applications written in C# use the .NET Framework, so it makes sense to use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.

C Syntax: 

 C# file called Program.cs, and we used the following code to print "Hello World" to the screen


Define each and every line which shown in the picture.

Line 1: using System means that we can use classes from the System namespace.

Line 2: A blank line. C# ignores white space. However, multiple lines makes the code more readable.

Line 3: namespace is used to organize your code, and it is a container for classes and other namespaces.

Line 4: The curly braces {} marks the beginning and the end of a block of code.

Line 5: class is a container for data and methods, which brings functionality to your program. Every line of code that runs in C# must be inside a class. In our example, we named the class Program.

Don't worry if you don't understand how using System, namespace and class works. Just think of it as something that (almost) always appears in your program, and that you will learn more about them in a later chapter.

Line 7: Another thing that always appear in a C# program is the Main method. Any code inside its curly brackets {} will be executed. You don't have to understand the keywords before and after Main. You will get to know them bit by bit while reading this tutorial.

Line 9: Console is a class of the System namespace, which has a WriteLine() method that is used to output/print text. In our example, it will output "Hello World!".

Note: 

  1. Every C# statement ends with a semicolon ;.
  2.  C# is case-sensitive; "MyClass" and "myclass" have different meaning.

C# Output

To output values or print text in C#, we can use the WriteLine() method
WriteLine() methods as you want. Note that it will add a new line for each method:



C# Single line Comment & Multi Line Comment

Comments can be used to explain C# code, and to make it more readable. It can also be used to prevent execution when testing alternative code.

  • Single-line Comments (//)
Single-line comments start with two forward slashes (//).

Any text between // and the end of the line is ignored by C# (will not be executed).

This example uses a single-line comment at the end of a line of code: we can see in the image single line comment.

  • C# Multi-line Comments
Multi-line comments start with /* and ends with */.

Any text between /* and */ will be ignored by C#.

This example uses a multi-line comment (a comment block) to explain the code we see in the image multiline comments.





Post a Comment

0 Comments