C# Tutorial
C# Tutorial
C# tutorial provides basic and advanced concepts of C#. Our C# tutorial is designed for
beginners and professionals.
Our C# tutorial includes all topics of C# such as first example, control statements, objects
and classes, inheritance, constructor, destructor, this, static, sealed, polymorphism,
abstraction, abstract class, interface, namespace, encapsulation, properties, indexer, arrays,
strings, regex, exception handling, multithreading, File IO, Collections etc.
C# History
History of C# language is interesting to know. Here we are going to discuss brief history
of C# language.
It is based on C++ and Java, but it has many additional extensions used to perform
component oriented programming approach.
C# has evolved much since their first release in the year 2002. It was introduced with .NET
Framework 1.0and the current version of C# is 5.0.
Let's see the important features introduced in each version of C# are given below.
What is C#
C# is pronounced as "C-Sharp". It is an object-oriented programming language provided by
Microsoft that runs on .Net Framework.
By the help of C# programming language, we can develop different types of secured and
robust applications:
o Window applications
o Web applications
o Distributed applications
o Web service applications
o Database applications etc.
C# is approved as a standard by ECMA and ISO. C# is designed for CLI (Common Language
Infrastructure). CLI is a specification that describes executable code and runtime
environment.
C# tutorial provides basic and advanced concepts of C#. Our C# tutorial is designed for beginners and
professionals.
Our C# tutorial includes all topics of C# such as first example, control statements, objects and classes,
inheritance, constructor, destructor, this, static, sealed, polymorphism, abstraction, abstract class,
interface, namespace, encapsulation, properties, indexer, arrays, strings, regex, exception handling,
multithreading, File IO, Collections etc.
C# Features
C# is object oriented programming language. It provides a lot of features that are given
below.
1. Simple
2. Modern programming language
3. Object oriented
4. Type safe
5. Interoperability
6. Scalable and Updateable
7. Component oriented
8. Structured programming language
9. Rich Library
10. Fast speed
1)Simple
C# is a simple language in the sense that it provides structured approach (to break the
problem into parts), rich set of library functions, data types etc.
3) Object Oriented
C# is object oriented programming language. OOPs makes development and maintenance
easier where as in Procedure-oriented programming language it is not easy to manage if
code grows as project size grow.
4) Type Safe
C# type safe code can only access the memory location that it has permission to execute.
Therefore it improves a security of the program.
5) Interoperability
Interoperability process enables the C# programs to do almost anything that a native C++
application can do.
7) Component Oriented
C# is component oriented programming language. It is the predominant software
development methodology used to develop more robust and highly scalable applications.
9) Rich Library
C# provides a lot of inbuilt functions that makes the development fast.
10) Fast Speed
The compilation and execution time of C# language is fast.
C++ vs C#
There are many differences and similarities between C++ programming language and C#. A
list of top differences between C++ and C# are given below:
No. C++ C#
4) In C++, pointers can be used anywhere in a program. In C#, pointers can be used on
N
Java vs C#
There are many differences and similarities between Java and C#. A list of top differences
between Java and C# are given below:
No. Java C#
4) In java, built-in data types that are passed by value are In C#, built-in data types that a
called primitive types. are called simple types.
8) Java doesn't support structures and unions. C# supports structures and unio
o Simple Example
o Using System
o Using public modifier
o Using namespace
C# Simple Example
1. class Program
2. {
3. static void Main(string[] args)
4. {
5. System.Console.WriteLine("Hello World!");
6. }
7. }
Output:
Hello World!
Description
class: is a keyword which is used to define class.
Program: is the class name. A class is a blueprint or template from which objects are
created. It can have data members and methods. Here, it has only Main method.
static: is a keyword which means object is not required to access static members. So it
saves memory.
void: is the return type of the method. It does't return any value. In such case, return
statement is not required.
Main: is the method name. It is the entry point for any C# program. Whenever we run the
C# program, Main() method is invoked first before any other method. It represents start up
of the program.
string[] args: is used for command line arguments in C#. While running the C# program,
we can pass values. These values are known as arguments which we can use in the
program.
1. using System;
2. class Program
3. {
4. static void Main(string[] args)
5. {
6. Console.WriteLine("Hello World!");
7. }
8. }
Output:
Hello World!
1. using System;
2. public class Program
3. {
4. public static void Main(string[] args)
5. {
6. Console.WriteLine("Hello World!");
7. }
8. }
Output:
Hello World!
1. using System;
2. namespace ConsoleApplication1
3. {
4. public class Program
5. {
6. public static void Main(string[] args)
7. {
8. Console.WriteLine("Hello World!");
9. }
10. }
11. }
Output:
Hello World!