Day-1
Day-1
C# is used for:
● Mobile applications
● Desktop applications
● Web applications
● Web services
● Web sites
● Games
● VR
● Database applications
● And much, much more
Reasons to use c#
● It is one of the most popular programming language in the world
● It is easy to learn and simple to use
● It has a 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
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Example explaination
1 using System means that we can use classes from the System namespace.
2: namespace is used to organize your code, and it is a container for classes and
other namespaces.
3: The curly braces {} marks the beginning and the end of a block of code.
4: class is a container for data and methods. Every line of code that runs in C#
must be inside a class. In our example, we named the class Program.
5: The Main method: Any code inside its curly brackets {} will be executed
Note: When saving the file, save it using a proper name and add ".cs" to the end of
the filename.
1.3 C# Variables
A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in C# has a specific type, which determines the size and
layout of the variable's memory the range of values that can be stored within that
memory and the set of operations that can be applied to the variable.
Rules to create variable name:
● The name can contain letters, digits, and the underscore character (_).
● The first character of the name must be a letter or underscore. C# is
case-sensitive;
● C# keywords can't be used as variable names.
● Syntax: type variableName = value;
Example string name = "Rohit";
1.4 C# identifier
In programming languages, identifiers are used for identification purposes. Or in
other words, identifiers are the user-defined name of the program components. In
C#, an identifier can be a class name, method name, variable name, or label.
Rules for defining identifiers in C#:
in (generic
In int interface
modifier)
out (generic
Operator Out override
modifier)
using
Unsafe Ushort using
static