0% found this document useful (0 votes)
53 views

Introduction To C

The document provides an introduction to C# and the .NET framework. It discusses the history and development of C#, an overview of why C# is widely used, and how to create a basic "Hello World" console application in C#. It also covers basic C# concepts like variables, data types, operators, loops, and input/output to the console.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Introduction To C

The document provides an introduction to C# and the .NET framework. It discusses the history and development of C#, an overview of why C# is widely used, and how to create a basic "Hello World" console application in C#. It also covers basic C# concepts like variables, data types, operators, loops, and input/output to the console.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

INTRODUCTION to C#

.NET Framework

.NETFramework(pronounceddot net)isasoftwareframework
developedbyMicrosoftthatrunsprimarilyonMicrosoftWindows

The.NETframeworkisarevolutionaryplatformthathelpsyouto
writethefollowingtypesofapplications:
Windowsapplications
Webapplications
Webservices

History of C#

DevelopedbyAndersHejlsberg(Microsoft).from
Denmark.

BasedonJavaandC++,buthasmanyadditional
extensions.

Cross-developmentwithVisualBasic,VisualC++,
F#,IronPython,andmanyother.NETlanguages

Overview
The following reasons make C# a widely used professional
language:
Modern,general-purposeprogramminglanguage.
Objectoriented.
Easytolearn.
Structuredlanguage.
Producesefficientprograms.
Partof.NETFramework.

C# console based application


Hello World - Your First Program
InordertocreateaC#consolebasedapplication.

OpenyourVisual Studio
OntheFilemenu,clickNewProject.
ThentheNewProjectdialogboxappears.Thisdialogboxliststhe
differentdefaultapplicationtypes.
SelectConsoleApplicationasyourprojecttypeandchangethenameof
yourapplicationatthebottomtextbox.
Ifyouarenotcomfortablewithdefaultlocation,youcanalwaysentera
newpathifyouwant.
ThenClickOK.
AfterclickOKbutton,youwillgetascreenlikethefollowingpicture.

In this session

Basicstructureofac#program.

WhatisaNamespace.

PurposeofMainmethod.

Simple Program

Program Explanation

Thefirstlineoftheprogramusing System; -theusing keywordisusedto


includetheSystem namespaceintheprogram.Aprogramgenerallyhasmultiple
using statements.

Thenextlinehasthenamespace declaration.Anamespace isacollectionof


classes.

Anamespaceisusedtoorganizeyourcode.

TheHelloWorldApplication namespacecontainstheclassHelloWorld.

Thenextlinehasaclass declaration,theclassHelloWorld containsthedataand


methoddefinitionsthatyourprogramuses.Classesgenerallycontainmultiple
methods.Methodsdefinethebehavioroftheclass.However,theHelloWorld
classhasonlyonemethodMain.

Mainmethodistheentrypointintoyourapplication.

Sample program

Output

Reading and Writing to Console


Inthissession
Readingfromtheconsole
Writingtotheconsole
2waystowritetoconsole

A) Concatenation
B) Placeholdersyntax-MostPreferred

Sample pgm (Read & write)


usingSystem;
classProgram
{
staticvoidMain(string[]args)
{
//Prompttheuserforhisname
Console.WriteLine("Pleaseenteryourname");
//Readthenamefromconsole
stringUsername=Console.ReadLine();
//Concatenatenamewithhellowordandprint
Console.WriteLine("Hello"+Username);
//Placeholdersyntaxtoprintnamewithhelloword
//Console.WriteLine("Hello{0}",Username);
}}

Output

Arithmetic operator

Output

Comparison operator

Output

Conditional operator(And)

Conditional
operator(OR)

Ternary operator without use

Ternary use

How to use C# for loop


For loop:
Aforloopisarepetitioncontrolstructurethatallowsyouto
efficientlywritealoopthatneedstoexecuteaspecificnumberoftimes.
Syntax:

for ( init; condition; increment )


{
statement(s);
}

Example:
for(inta=10;a<20;a=a+1)
{
Statements(s);
}

Flow chart(For Loop)

Output

How to use C# while loop


while loop:
Thewhilestatementcontinuallyexecutesablockof
statementsuntilaspecifiedexpressionevaluatestofalse.
Syntax:
while(condition)
{
statement(s);
}

Flow chart(while loop)

C# windows based application

Output

You might also like