Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

UNIT-1

BASICS OF C#
ITRODUCTION
• 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.
.NET Framework

• .NET is a framework to develop software applications. It is


designed and developed by Microsoft and the first beta version
released in 2000.
• It is used to develop applications for web, Windows, phone.
Moreover, it provides a broad range of functionalities and
support.
• This framework contains a large number of class libraries
known as Framework Class Library (FCL). The software
programs written in .NET are executed in the execution
environment, which is called CLR (Common Language Runtime).
These are the core and essential parts of the .NET framework.
HISTORY OF C#
• C# is pronounced as "C-Sharp". It is an object-oriented
programming language provided by Microsoft that runs on
.Net Framework.
• Anders Hejlsberg is known as the founder 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.0 and the
current version of C# is 5.0.
C# Features

• Simple
• Modern programming language
• Object oriented
• Type safe
• Interoperability
• Scalable and Updateable
• Component oriented
• Structured programming language
• Rich Library
• Fast speed
C# PROGRAM STRUCTURE
• Library invoked by the keyword "using".
• Declaring namespace using the "namespace"
keyword.
• Declaring a class using the keyword "class".
• Class members and attributes.
• The Main() method.
• Other statements and expressions.
• Writing comments for user understanding and non-
executable statements.
using System;
namespace printHelloCsharp
{
class HelloCsharp
{
static void Main(string[] args)
{
Console.WriteLine("Hello C#."); Console.ReadKey();
}}}
C# Variable

• variable is a name of memory location. It is used to store data.


Its value can be changed and it can be reused many times.
• It is a way to represent memory location through symbol so
that it can be easily identified.
• The basic variable type available in C# can be categorized as:
Rules for defining variables

• A variable can have alphabets, digits and


underscore.
• A variable name can start with alphabet and
underscore only. It can't start with digit.
• No white space is allowed within variable
name.
• A variable name must not be any reserved
word or keyword e.g. char, float etc.
C# Data Types
C# Type Casting

• In C#, there are two types of casting:


• Implicit Casting (automatically) - converting a smaller
type to a larger type size
char -> int -> long -> float -> double

Explicit Casting (manually) - converting a larger type


to a smaller size type
double -> float -> long -> int -> char
• Example:
• Convert.ToInt32(myDouble)
C# User Input

• string userName = Console.ReadLine();


• It will only input string if we want to enter
other data type value than we want to do
explicit type casting.
• Example:
• int age = Convert.ToInt32(Console.ReadLine());
C# Operators

• Arithmetic Operators
• C# Comparison Operators
• C# Logical Operators
C# If ... Else

Synatx:
if (condition1)
{ // block of code to be executed if condition1 is True
}
else if (condition2)
{ // block of code to be executed if the condition1 is false and condition2
is True
}
else
{ // block of code to be executed if the condition1 is false and condition2
is False
}
• While( condition)
• {
• ------body while loop
• }

You might also like