Friday, May 29, 2020

C# For Beginners

C# Tutorials For Beginners

C# (C-Sharp) is a programming language developed by Microsoft that runs on the .NET Framework.
C# is used to develop web apps, desktop apps, mobile apps, games and much more.
C# is pronounced "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# 8, was released in September 2019.
C# is used for:
  • Mobile applications
  • Desktop applications
  • Web applications
  • Web services
  • Web sites
  • Games
  • VR
  • Database applications
  • And much, much more!
Why 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
C# IDE
The easiest way to get started with C#, is to use an IDE.
An IDE (Integrated Development Environment) is used to edit and compile code.
Link to download visual studio: 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.

My first C# program

using System;

namescape Firstprogaram
{

class Program
{
static void Main(string[] args)
{

console.wrteline.("hello world");
}
}
}

Characteristics of C#

the main design goal of c# was simplicity rathar than pure power. C# fulfills the needs fo a language that is easy to write read and maintain and also provide the power and flexibility of c++. the language that is designed for both computing and comunications is characterized by the several key features.It is.

# simple
# consistent
# Modern
# Object-oriented
# type safe
# Versonable
# compatible
# interoperable
# Flexible

Simple
C# simplifies C++ by eliminating irksome operations such as->:: and pointers> C# treates integer and Boolean data types and two entirely different types. this means that the use of = in place of == in if statement will be caught by the comiler.

Consistent
C# supports an unified type system which is elimintes the problem of varingranges of integer types. all types are treated as object and developers can extend the type system simply and easily.

Modern
C# is called a modern language due to a number of features it supports.It supports
* Automatic Garbage collection
* Rich intrinsic model for error handling
* Decimal data type for financial application
* Modern approach to debugging and
* Robust security model

Object-Oriented
C# is truely object-oriented. It supports all the three tenents namely of object-oriented sysytem, namely.
* Encapsulation
* Inheritance
* Polymorphism

the entire C# model is built on top of the virtual object System(VOS) of the .Net Framework. In C#,everything is an object. 
There are no more global functions,variables and constants.

Type-safe
Type-safety promotes robust programs.C# incorporates a number of type safe measures.
* All dynamically allocated objects and arrays are initialize to zero.
* Use of any uninitialized variables produces an error message by the compiler
* Access to array are ranged check and warned ig out of bounds.
* C# does not permit unsafe casts
* C# enforces overflow checking in arithmetic operation
* Reference parameter passed are passed as type-safe
* C# supports automatic garbage collection

Versionable
Making new versions of software modules work with the existing application is known as versioning.C# provide support for versioning with the help of new and override keywords.With this support a programmer can guarantee that his new class library will maintain binary compatibility with the existing client application.

Compatibility
C# enforces the .Net common language specification and therefore allows inter-operation with other .Net language

 C# Program:

using System; <--Namespace
 
 
namespace Firstday
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("First day today");
        }
    }
}

The namespace declaration, using System, indicates that you are using the System namespace. If  you omit the using System, declaration, then you have to use the fully qualified name of the Console class. A namespace is used to organize your code and is collection of classes, interfaces, structs, enums and delegates. 

 Main() method - Main method is the entry point into your application.





 Program:



How to get input from the used and show on the console

using System;
 
 
namespace Firstday
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("First day today");
            
            Console.WriteLine("Please enter your name");
       
            string Name = Console.ReadLine();
           
            Console.WriteLine("Hello " + Name);
 
        }
    }
}

Build Type in C#

1. Boolean type – Only true or false 2. Integral Types - sbyte, byte, short, ushort, int, uint, long, ulong, char3. Floating Types – float and double4. Decimal Types 5. String Type

Escape sequences in c#