0% found this document useful (0 votes)
49 views

C#Lecture

C# is a general-purpose, modern programming language developed by Microsoft for building a variety of applications. A simple C# program is presented that uses Console.WriteLine to print "Hello Geeks" and Console.ReadKey to pause the program. Key features of C# include garbage collection, compatibility with .NET, and use for desktop, web, and game applications.

Uploaded by

Lorence Dhlakama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

C#Lecture

C# is a general-purpose, modern programming language developed by Microsoft for building a variety of applications. A simple C# program is presented that uses Console.WriteLine to print "Hello Geeks" and Console.ReadKey to pause the program. Key features of C# include garbage collection, compatibility with .NET, and use for desktop, web, and game applications.

Uploaded by

Lorence Dhlakama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C# 

is a general-purpose, modern and object-oriented programming language


pronounced as “C sharp”. It was developed by Microsoft led by Anders
Hejlsberg and his team within the .
Example: A simple program to print Hello Geeks
// C# program to print Hello Geeks
using System;
  
namespace HelloGeeksApp
{   
    class HelloGeeks
    {   
        // Main function
        static void Main(string[] args)
        {
  
            // Printing Hello Geeks
            Console.WriteLine("Hello Geeks");
  
            Console.ReadKey();
        }
    }

Output:
Hello Geeks
Explanation:
1. Comments: Comments are used for explaining code and are used in similar
manner as in Java or C or C++. Compilers ignore the comment entries and
does not execute them. Comments can be of single line or multiple lines.
Single line Comments:
Syntax:
// Single line comment
Multi line comments:
Syntax:
/* Multi line comments*/
2. using System: using keyword is used to include the System namespace in
the program.
namespace declaration: A namespace is a collection of classes. The
HelloGeeksApp namespace contains the class HelloGeeks.
3. class: The class contains the data and methods to be used in the program.
Methods define the behavior of the class. Class HelloGeeks has only one
method Main similar to JAVA.
4. static void Main(): static keyword tells us that this method is accessible
without instantiating the class. 5. void keywords tells that this method will not
return anything. Main() method is the entry-point of our application. In our
program, Main() method specifies its behavior with the statement
Console.WriteLine(“Hello Geeks”); .
6. Console.WriteLine(): WriteLine() is a method of the Console class defined
in the System namespace.
7. Console.ReadKey(): This is for the VS.NET Users. This makes the program
wait for a key press and prevents the screen from running and closing quickly.
Note: C# is case sensitive and all statements and expressions must end with
semicolon (;).
Advantages of C#:
 C# is very efficient in managing the system. All the garbage is automatically
collected in C#.
 There is no problem of memory leak in C# because of its high memory
backup.
 Cost of maintenance is less and is safer to run as compared to other
languages.
 C# code is compiled to a intermediate language (Common (.Net)
Intermediate Language) which is a standard language, independently
irrespective of the target operating system and architecture.
Disadvantages of C#:
 C# is less flexible as it depends alot on .Net framework.
 C# runs slowly and program needs to be compiled each time when any
changes are made.
Applications:
 C# is widely used for developing desktop applications, web applications and
web services.
 It is used in creating applications of Microsoft at a large scale.
 C# is also used in game development in Unity.

You might also like