C# (pronounced as C sharp) is a general-purpose, object-oriented programming language. It is one of the most popular languages used for developing desktop and web applications. Being a high-level language, the basic constructs of C# is easy to understand. It is closer to other popular languages like Java and C++. Hence, it is very easy for someone with experience in these programming languages to switch to C#.
The code written in C# is much simpler and easier to understand. It is syntactically very similar to Java. Hence, for a person with experience in Java, C# won't be a difficult language to learn.
Like Java and C++, C# is an object-oriented programming language. It supports the features of object-oriented paradigms such as objects, classes, inheritance, polymorphism, etc.
A type-safe language ensures that each variable of a particular type does not hold values of other types. For example, an integer variable will not hold character values.
C# is a modern and powerful language that allows developers to build robust applications quickly and easily. It is built based on the current trend.
The “Hello World!” program is often the first program we see when we dive into a new language. It simply prints Hello World! on the output screen.
The purpose of this program is to get us familiar with the basic syntax and requirements of a programming language.
// Hello World! program
namespace HelloWorld
{
class Hello
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
}
When you run the program, the output will be:
Hello World!
Keywords are predefined sets of reserved words that have special meaning in a program. The meaning of keywords can not be changed, neither can they be directly used as identifiers in a program.
For example,
long mobileNum;
Here, long is a keyword and mobileNum is a variable (identifier). long has a special meaning in C# i.e. it is used to declare variables of type long and this function cannot be changed.
Also, keywords like long, int, char, etc can not be used as identifiers. So, we cannot have something like:
long long;
Identifiers are the name given to entities such as variables, methods, classes, etc. They are tokens in a program which uniquely identify an element. For example,
int value;
Here, value is the name of variable. Hence it is an identifier. Reserved keywords can not be used as identifiers unless @ is added as prefix. For example,
int break;
This statement will generate an error in compile time.
An identifier can not be a C# keyword. An identifier must begin with a letter, an underscore or @ symbol.
The remaining part of identifier can contain letters, digits and underscore symbol.
Whitespaces are not allowed. Neither it can have symbols other than letter, digits and underscore.
Identifiers are case-sensitive. So, getName, GetName and getname represents 3 different identifiers.