SlideShare una empresa de Scribd logo
1 de 14
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 2
What is the C# Programming Language?
C# (pronouncedas“C Sharp”) is a simple,modern,object-oriented,andtype-safeprogramminglanguage.C#
language hasitsroots inC languagessuchasC, C++, andit ismostlysimilartoJavaprogramming.
C# is a stronglytypedobject-orientedprogramminglanguage.C#isopensource,simple,modern,flexible,and
versatile.Inthisarticle,letuslearnwhatC#is,what C# can do,and how C# is differentfromC++ andother
programminglanguages.
C# is a programminglanguage of .NetFramework.
C# is pronouncedas"C-Sharp".Itis an object-orientedprogramminglanguage providedbyMicrosoftthatruns on
.NetFramework.
C# is a programminglanguage developedandlaunchedbyMicrosoftin2001. C# is a simple,modern,andobject-
orientedlanguage thatprovidesmoderndaydevelopersflexibilityandfeaturestobuildsoftwarethatwill notonly
worktoday butwill be applicable foryearsinthe future.
A programminglanguage oncomputerscience isalanguage thatis usedto write software programs.
C# Programminglanguage will allowdeveloperstobuildavarietyof secure androbustapplicationssuchas
windowsapplications,webapplications,database applications,etc.,whichwill runon .NETFramework.
C# programminglanguage hasbeenbuilton .NETFramework torun the C# applications.We are requiredtoinstall
a .NET Framework componentonourmachines.
.NET Framework isa developmentplatformforbuildingappsforwindows,web,azure,etc.,byusingprogramming
languagessuchas C#, F#, and Visual Basic.Itconsistsof twomajor components,suchas CommonLanguage
Runtime (CLR),anexecutionenginethathandlesrunningapps,and .NETFrameworkClassLibrary,whichprovidesa
libraryof testedandreusable code thatdeveloperscanuse itintheirapplications.
C# Features
C# is object oriented programming language. It provides many features that are given below.
Simple
Modernprogramminglanguage
Objectoriented
Type safe
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 3
Interoperability
Scalable andUpdateable
Componentoriented
Structuredprogramminglanguage
Rich Library
Fast speed
Modernand easy
Fast and opensource
Crossplatform
Safe
Versatile
Simple
C# is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of
library functions, data types etc.
ModernProgramming Language
C# programming is based upon the current trend and it is very powerful and simple for building scalable,
interoperable and robust applications.
ObjectOriented
C# is object oriented programming language. OOPs makes development and maintenance easier where as in
Procedure-oriented programming language it is not easy to manage if code grows as project size grow.
Type Safe
C# type safe code can only access the memory location that it has permission to execute. Therefore,it improves a
security of the program.
Interoperability
Interoperability process enables the C# programs to do almost anything that a native C++ application can do.
Scalable and Updateable
C# is automatic scalable and updateable programming language. For updating our application, we delete the old files
and update them with new ones.
ComponentOriented
C# is component oriented programming language. It is the predominant software development methodology used to
develop more robust and highly scalable applications.
Structured Programming Language
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 4
C# is a structured programming language in the sense that we can break the program into parts using functions.
Therefore,it is easy to understand and modify.
Rich Library
C# provides many inbuilt functions that makes the development fast.
Fast Speed
The compilation and execution time of C# language is fast.
C# is modern and easy
C# is a simple,modern,andanobject-orientedprogramminglanguage.The purpose of C#was to developa
programminglanguage thatisnot onlyeasytolearnbut alsosupportsmoderndayfunctionalityforall kindof
software development.
If you lookat the historyof programminglanguagesandtheirfeatures,eachprogramminglanguage wasdesigned
for a specificpurpose tosolve aspecificneedatthat time.
C# language howeverwas designedtokeepbusinessandenterprisesneedsinmind.C#language wasdesignedfor
businessestobuildall kindsof software byusingone single programminglanguage.
C# providesfunctionalitytosupportmoderndaysoftware development.C#supportsWeb,Mobile,andapp
developmentneeds.Some of the modern-dayprogramminglanguagefeaturesC#supportsare generics,vartypes,
auto initializationof typesandcollections,lambdaexpressions,dynamicprogramming,asynchronousprogramming,
tuples,pattern matching,advanceddebuggingandexceptionhandling,andmore.
C# language syntaxesare influencedfromC++,Java, Pascal and few otherlanguagesthatare easyto adopt.C# also
avoidscomplexityandunstructuredlanguagefeatures.
C# is fast and opensource
C# is opensource underthe .NET Foundation,whichisgovernedandrunindependentlyof Microsoft.C#language
specifications,compilers,andrelatedtoolsare opensource projectsonGitHub.While C#language feature designis
ledbyMicrosoft, the opensource communityisveryactive inthe language developmentandimprovements.
C# is fastcompare to several otherhigh-level programminglanguages.C#8 has manyperformance improvements.
C# is cross platform
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 5
C# is cross platformprogramming language.Youcan build.NETapplicationsthatcanbe deployedonWindows,
Linux,andMac platforms.C#apps can alsobe deployedincloudandcontainers.
C# is safe and efficient
C# is a type safe language.C#doesnot allowtype conversionsthatmay leadto data lossor otherproblems.C#
allowsdeveloperstowrite safe code.C#alsofocusesonwritingefficientcode.
Here is a listof some of the keyconceptsinC# that helpswrite safe andefficientcode.
Unsafe type castingisnot allowed.
Nullable andnon-null abletypesare supportedinC#.
Declare a readonlystructto expressthata type isimmutable andenablesthe compilertosave copieswhenusingin
parameters.
Use a ref readonlyreturnwhenthe returnvalue isa structlarger thanIntPtr.Size andthe storage lifetime isgreater
than the methodreturningthe value.
Whenthe size of a readonlystructisbiggerthanIntPtr.Size,youshouldpassitasan in parameterforperformance
reasons.
Neverpassa struct as an inparameterunlessitis declaredwiththe readonlymodifierbecauseitmaynegatively
affectperformance andcouldleadtoan obscure behavior.
Use a ref struct, or a readonlyref structsuch as Span<T> or ReadOnlySpan<T>towork withmemoryasa sequence
of bytes.
C# is versatile
C# is a Swissarmyknife.While mostprogramminglanguagesweredesignedforaspecificpurpose,C#wasdesigned
to do C#. We can use C# to buildtoday’smodernsoftware applications.C#can be usedto developall kindof
applicationsincludingWindows clientapps,componentsandlibraries,servicesandAPIs,Webapplications,Mobile
apps,cloudapplications,andvideogames.
Here is a listof typesof applicationsC#can build:
Windowsclientapplications
Windowslibrariesandcomponents
Windowsservices
Webapplications
WebservicesandWebAPI
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 6
Native iOSandAndroidmobile apps
Backendservices
Azure cloudapplicationsandservices
Backenddatabase usingML/Data tools
InteroperabilitysoftwaresuchasOffice,SharePoint,SQLServerandsoon.
Artificial IntelligenceandMachine learning
Blockchainsand distributedledgertechnologyincludingcryptocurrency
Internetof Things(IoT) devices
Gamingconsolesandgamingsystems
Videogames
C# History
History of C# language isinterestingtoknow.Here we are goingto discussbrief historyof C#language.C#is
pronouncedas "C-Sharp".Itis an object-orientedprogramminglanguage providedby Microsoftthatruns on .Net
Framework. AndersHejlsbergisknownas the founderof C# language.
It isbasedon C++ and Java, but ithas many additional extensionsusedtoperformcomponentoriented
programmingapproach.
C# has evolvedmuchsince theirfirstrelease inthe year 2002. It was introducedwith .NETFramework 1.0 and the
currentversionof C# is 10.0.
C# Version History
C# was first introduced with .NET Framework 1.0 in the year 2002 and evolved much since then. The
following table lists important features introduced in each version of C#:
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 7
Version .NET Framework Visual Studio Important Features
C# 1.0 .NET Framework 1.0/1.1 Visual Studio .NET 2002 Basic features
C# 2.0 .NET Framework 2.0 Visual Studio 2005
Generics
Partial types
Anonymous methods
Iterators
Nullable types
Private setters (properties)
Method group conversions (delegates)
Covariance and Contra-variance
Static classes
C# 3.0 .NET Framework 3.03.5 Visual Studio 2008
Implicitly typed local variables
Object and collection initializers
Auto-Implemented properties
Anonymous types
Extension methods
Query expressions
Lambda expressions
Expression trees
Partial Methods
C# 4.0 .NET Framework 4.0 Visual Studio 2010
Dynamic binding (late binding)
Named and optional arguments
Generic co- and contra variance
Embedded interop types
C# 5.0 .NET Framework 4.5 Visual Studio 2012/2013
A sync features
Caller information
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 8
Version .NET Framework Visual Studio Important Features
C# 6.0 .NET Framework 4.6 Visual Studio 2013/2015
Expression Bodied Methods
Auto-property initializer
name of Expression
Primary constructor
Await in catch block
Exception Filter
String Interpolation
C# 7.0 .NET Core 2.0 Visual Studio 2017
out variables
Tuples
Discards
Pattern Matching
Local functions
Generalized a sync return types
C# 8.0 .NET Core 3.0 Visual Studio 2019
Read-only members
Default interface methods
Using declarations
Static local functions
Disposable ref structs
Nullable reference types
More
C# 9.0 .NET 5.0 Visual Studio 2019
Records
Init-only properties
Top-level statements
Init accessors and readonly fields
With-expressions
Value-based equality
more
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page | 9
Version .NET Framework Visual Studio Important Features
C# 10.0 .NET 6.0 Visual Studio 2022
Record structs
Global using directives
File-scoped namespace declaration
Extended Proptery Patterns
Null Parameter Checking
Constant interpolated strings
more
C# Example:HelloWorld
In C# programming language, a simple "hello world" program can be written by multiple ways. Let us see the top
four ways to create a simple C# example:
Simple Example
Using System
Using public modifier
Using namespace
C# Simple Example
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
Output:
Hello World!
Description
class: is a keyword, which is used to define class.
Program: is the class name. A class is a blueprint or template from which objects are created. It can have data
members and methods. Here,it has only Main method.’ static: is a keyword that means object is not required to
access static members. So it saves memory.
void: is the return type of the method. It does't return any value. In such case,return statement is not required.
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page |
10
Main: is the method name. It is the entry point for any C# program. Whenever we run the C# program, Main()
method is invoked first before any other method. It represents start up of the program.
string[] args: is used for command line arguments in C#. While running the C# program, we can pass values. These
values are known as arguments which we can use in the program.
System.Console.WriteLine("Hello World!"): Here,System is the namespace. Console is the class defined in
System namespace. The WriteLine() is the static method of Console class which is used to write the text on the
console.
C# Example: Using System
If we write using Systembefore the class,it means we don't need to specify System namespace for accessing any
class of this namespace. Here,we are using Console class without specifying System.Console.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
Output:
Hello World!
C# Example: Using public modifier
We can also specify public modifier before class and Main() method. Now, it can be accessed from outside the class
also.
using System;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
Output:
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page |
11
Hello World!
C# Example: Using namespace
We can create classes inside the namespace. It is used to group related classes. It is used to categorize classes so that
it can be easy to maintain.
using System;
namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Output:
C# Program Structure
A typical C# Program consists ofseveral different parts as shown below:
Namespace
Class
The main method
Methods inside the class
Class definition or class attributes
Statements
Comments
Few things need to be kept in mind while writing a C# program. C# programs are case sensitive, which means
“string” is different from “String”. All the statements written in the program must be concluded with a semicolon i.e.
“;”. A semicolon tells the program that the current line of the statement has ended.
Hello World!
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page |
12
As discussed earlier, the execution of the C# program starts from the Main method, hence the program should have
the Main method as its starting point.
Before we begin with an explanation ofthe C# components lets recall a fewpoints:
A program needs to have a reference to the .Net framework that has been used in the program.
For our current program to reference.Net,we use “using”. For Example “using System” in our above program.
After defining the references we declare a namespace. Syntax Example- namespace ConsoleApplication.
Then we declared a class using a class keyword. Syntax Example- class Program.
Inside the class, we have a Main method. This is the starting point of the execution.
Inside the Main method, we have defined “Console” which is a class in the .Net framework. The “WriteLine()” is a
method that is used to display a message in a console. Similar to “WriteLine()”, “ReadLine()” is also a method
that reads user input.
In the above program, we wrote a text in the console application and discussed various parts of the program. Here,
we will discuss various parts that were used in conjuncture with each other to make-up a valid syntax in detail. We
will discuss components, their definition and ways in which we have to declare them in the program.
Using Keyword
The using keyword is used to handle any object that is being used to implement the namespace. It is used to import a
namespace. As a namespace is a collection of classes and each class has its own functionality, so using the keyword
provides us with the facility to implement different functionality from the namespace that has been imported.
Namespace
The namespace is a collection of related classes and objects. It is designed to offer a way to keep a different set of
objects segregated from each other. This allows the programmers to declare one class inside a namespace and another
class inside another namespace without causing a conflict.
Let us say we are creating two namespaces namely “fruits” and “colors”. Both these namespaces can have a class
called “Orange” without creating any conflict with each other. A namespace is defined by writing your namespace
name preceded by keyword namespace.
For Example: namespace ConsoleApplication
Class
Defining a class is similar to defining a blueprint of a data type. Class does not actually define the data but they
arrange the data as a meaningful entity.
For Example,if we have a class called “Fruit”, and then we can specify different related objects inside the class such
as mango, apple, grapes, etc. Thus, the class fruit will contain different fruit objects with different properties such as
color, taste, smell, edible, etc. Each of these objects and property will be a part of the class.
Similar to the above example, the object-oriented programming language such as C# also defines different properties
inside i.e. fields, methods, conditions, events, etc. The objects inside the class contain a definition of the operations
that can be performed.
Objects are an instance of the class and the methods or the variables that are the members of the class. Thus, in short,
the class allows you to create your own custom objects by grouping other methods, events and object types.
A class is defined by putting the keyword “class” before the name of the class and a pair of curly braces should
define the class body.
Department of Information Technology Event-Driven Programming C#
ETHIOPIAN POLICEUNIVERSITY Page |
13
class Program
{
// class body
}
Access Modifiers
Access modifiers define the accessibility of an object and its components. All the C# components have their own
access levelthat can be controlled by defining the scope of accessibility for the member objects inside the class by
using access modifiers.
To define the accessibility level of the object we have to declare it by using one of the keywords provided by C#
language i.e. Public, Private, Protected and Internal. Access modifier is declared by using of the keywords mentioned
above either before the class or a method.
Departmentof InformationTechnology Event-DrivenProgrammingC#
ETHIOPIAN POLICEUNIVERSITY
These arguments are useful while calling a method with certain parameters. In the above example, we
have passed only one parameter that is “args” with the argument type as an array of string.
Constructor
Constructors are the special methods in a class that is automatically invoked whenever an instance of the
particular class is created. The main advantage of the constructor is that it can initialize the private fields
of a class. A class can have a number of constructors and it does not need to have any return type.
Only one static constructor is allowed inside a class and that cannot be parameterized. Constructors are
declared by using any access modifier and then by using the class name in which it is created.
For Example, a constructor definition will look something like this.
class Program
{
public class(){ //This is a constructor
}
}
Data types are used in almost all the programming languages. A data type tells the compiler what kind of
value a variable will hold. C# has several built-in data types such as String, Integer, Float, Boolean, etc.
Each data type has its own set of definitions for the values it can hold.
A data type is used to declare a variable by the preceding variable with the data type keyword. class
Program
{
static void Main(string[]args)
{
string stringValue = "Hello"; int integerValue = 10;float floatValue = 13.2f;
bool booleanValue = false;
}
}
Curly Braces
We saw the extensive usage of curly braces “{}” in our previous programs and declarations which is why
it is referred to as one of the most important parts of any program. It defines the beginning and the end of
any logical statement in a program block.
Departmentof InformationTechnology Event-DrivenProgrammingC#
ETHIOPIAN POLICEUNIVERSITY
The curly braces are not only restricted to the C# language, but they are also found in several other
languages like Java,C++, etc. You can clearly see our first “Hello World” code that they are used to wrap
multiple lines of code together. It clearly marks the starting and the endpoint of the logical statement for
the compiler.
Any logical entity like Namespace,Class,Method, Conditional statement, Loops, etc. should be enclosed
inside braces to clearly mark the start and end of the statement for the compiler.

Más contenido relacionado

Similar a C# handout.docx

Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Similar a C# handout.docx (20)

DotNet Fundamentals
DotNet FundamentalsDotNet Fundamentals
DotNet Fundamentals
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
C#
C#C#
C#
 
C# Introduction brief
C# Introduction briefC# Introduction brief
C# Introduction brief
 
Characteristics of c#
Characteristics of c#Characteristics of c#
Characteristics of c#
 
C#
C#C#
C#
 
C#.ppt
C#.pptC#.ppt
C#.ppt
 
Intro1
Intro1Intro1
Intro1
 
C# chap 1
C# chap 1C# chap 1
C# chap 1
 
Ten compelling reasons to learn .net framework
Ten compelling reasons to learn .net frameworkTen compelling reasons to learn .net framework
Ten compelling reasons to learn .net framework
 
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
 
The Importance of C Language in the Tech Industry.pdf
The Importance of C Language in the Tech Industry.pdfThe Importance of C Language in the Tech Industry.pdf
The Importance of C Language in the Tech Industry.pdf
 
20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 
C-sharping.docx
C-sharping.docxC-sharping.docx
C-sharping.docx
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdfC# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdf
 
Chapter-1 C#.pptx
Chapter-1 C#.pptxChapter-1 C#.pptx
Chapter-1 C#.pptx
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 
Why C is Called Structured Programming Language
Why C is Called Structured Programming LanguageWhy C is Called Structured Programming Language
Why C is Called Structured Programming Language
 

Último

codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx
17duffyc
 
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
khuurq8kz
 
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
SaketCallGirlsCallUs
 
Van Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson todayVan Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson today
lucygibson17
 
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
delhimunirka15
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
dollysharma2066
 
Museum of fine arts Lauren Simpson…………..
Museum of fine arts Lauren Simpson…………..Museum of fine arts Lauren Simpson…………..
Museum of fine arts Lauren Simpson…………..
mvxpw22gfc
 
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknikppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
Agustinus791932
 
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
delhimunirka15
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Sheetaleventcompany
 
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
delhimunirka15
 
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
SaketCallGirlsCallUs
 
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
Nitya salvi
 

Último (20)

codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx
 
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
一比一原版美国西雅图大学毕业证(Seattle毕业证书)毕业证成绩单留信认证
 
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
Call Girls In Chattarpur | Contact Me ☎ +91-9953040155
 
Storyboard short: Ferrarius Tries to Sing
Storyboard short: Ferrarius Tries to SingStoryboard short: Ferrarius Tries to Sing
Storyboard short: Ferrarius Tries to Sing
 
Van Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson todayVan Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson today
 
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
9711106444 Ghaziabad, Call Girls @ ₹. 1500– Per Shot Per Night 7000 Delhi
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377087607
 
Museum of fine arts Lauren Simpson…………..
Museum of fine arts Lauren Simpson…………..Museum of fine arts Lauren Simpson…………..
Museum of fine arts Lauren Simpson…………..
 
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknikppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
ppt seni budaya kelas xi, menganalisis konsep,unsur,prinsip dan teknik
 
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
FULL ENJOY —📞9711106444 ✦/ Vℐℙ Call Girls in Jasola Vihar, | Delhi🫶
 
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service AvailableCall Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
 
New Call Girls In Shamli 8617370543 Shamli Escorts Service
New Call Girls In Shamli 8617370543 Shamli Escorts ServiceNew Call Girls In Shamli 8617370543 Shamli Escorts Service
New Call Girls In Shamli 8617370543 Shamli Escorts Service
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
 
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra  Escorts 📞 8617370543 | Sonbhadra Call GirlsSonbhadra  Escorts 📞 8617370543 | Sonbhadra Call Girls
Sonbhadra Escorts 📞 8617370543 | Sonbhadra Call Girls
 
Jaro je tady - Spring is here (Judith) 3
Jaro je tady - Spring is here (Judith) 3Jaro je tady - Spring is here (Judith) 3
Jaro je tady - Spring is here (Judith) 3
 
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
Pari Chowk Call Girls ☎️ ((#9711106444)), 💘 Full enjoy Low rate girl💘 Genuine...
 
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
Call Girls In Dilshad Garden | Contact Me ☎ +91-9953040155
 
Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4
 
Call Girls Bhavnagar - 📞 8617370543 Our call girls are sure to provide you wi...
Call Girls Bhavnagar - 📞 8617370543 Our call girls are sure to provide you wi...Call Girls Bhavnagar - 📞 8617370543 Our call girls are sure to provide you wi...
Call Girls Bhavnagar - 📞 8617370543 Our call girls are sure to provide you wi...
 
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
Russian Call Girls Lucknow Just Call 👉👉 📞 8617370543 Top Class Call Girl Serv...
 

C# handout.docx

  • 1. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 2 What is the C# Programming Language? C# (pronouncedas“C Sharp”) is a simple,modern,object-oriented,andtype-safeprogramminglanguage.C# language hasitsroots inC languagessuchasC, C++, andit ismostlysimilartoJavaprogramming. C# is a stronglytypedobject-orientedprogramminglanguage.C#isopensource,simple,modern,flexible,and versatile.Inthisarticle,letuslearnwhatC#is,what C# can do,and how C# is differentfromC++ andother programminglanguages. C# is a programminglanguage of .NetFramework. C# is pronouncedas"C-Sharp".Itis an object-orientedprogramminglanguage providedbyMicrosoftthatruns on .NetFramework. C# is a programminglanguage developedandlaunchedbyMicrosoftin2001. C# is a simple,modern,andobject- orientedlanguage thatprovidesmoderndaydevelopersflexibilityandfeaturestobuildsoftwarethatwill notonly worktoday butwill be applicable foryearsinthe future. A programminglanguage oncomputerscience isalanguage thatis usedto write software programs. C# Programminglanguage will allowdeveloperstobuildavarietyof secure androbustapplicationssuchas windowsapplications,webapplications,database applications,etc.,whichwill runon .NETFramework. C# programminglanguage hasbeenbuilton .NETFramework torun the C# applications.We are requiredtoinstall a .NET Framework componentonourmachines. .NET Framework isa developmentplatformforbuildingappsforwindows,web,azure,etc.,byusingprogramming languagessuchas C#, F#, and Visual Basic.Itconsistsof twomajor components,suchas CommonLanguage Runtime (CLR),anexecutionenginethathandlesrunningapps,and .NETFrameworkClassLibrary,whichprovidesa libraryof testedandreusable code thatdeveloperscanuse itintheirapplications. C# Features C# is object oriented programming language. It provides many features that are given below. Simple Modernprogramminglanguage Objectoriented Type safe
  • 2. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 3 Interoperability Scalable andUpdateable Componentoriented Structuredprogramminglanguage Rich Library Fast speed Modernand easy Fast and opensource Crossplatform Safe Versatile Simple C# is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functions, data types etc. ModernProgramming Language C# programming is based upon the current trend and it is very powerful and simple for building scalable, interoperable and robust applications. ObjectOriented C# is object oriented programming language. OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grow. Type Safe C# type safe code can only access the memory location that it has permission to execute. Therefore,it improves a security of the program. Interoperability Interoperability process enables the C# programs to do almost anything that a native C++ application can do. Scalable and Updateable C# is automatic scalable and updateable programming language. For updating our application, we delete the old files and update them with new ones. ComponentOriented C# is component oriented programming language. It is the predominant software development methodology used to develop more robust and highly scalable applications. Structured Programming Language
  • 3. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 4 C# is a structured programming language in the sense that we can break the program into parts using functions. Therefore,it is easy to understand and modify. Rich Library C# provides many inbuilt functions that makes the development fast. Fast Speed The compilation and execution time of C# language is fast. C# is modern and easy C# is a simple,modern,andanobject-orientedprogramminglanguage.The purpose of C#was to developa programminglanguage thatisnot onlyeasytolearnbut alsosupportsmoderndayfunctionalityforall kindof software development. If you lookat the historyof programminglanguagesandtheirfeatures,eachprogramminglanguage wasdesigned for a specificpurpose tosolve aspecificneedatthat time. C# language howeverwas designedtokeepbusinessandenterprisesneedsinmind.C#language wasdesignedfor businessestobuildall kindsof software byusingone single programminglanguage. C# providesfunctionalitytosupportmoderndaysoftware development.C#supportsWeb,Mobile,andapp developmentneeds.Some of the modern-dayprogramminglanguagefeaturesC#supportsare generics,vartypes, auto initializationof typesandcollections,lambdaexpressions,dynamicprogramming,asynchronousprogramming, tuples,pattern matching,advanceddebuggingandexceptionhandling,andmore. C# language syntaxesare influencedfromC++,Java, Pascal and few otherlanguagesthatare easyto adopt.C# also avoidscomplexityandunstructuredlanguagefeatures. C# is fast and opensource C# is opensource underthe .NET Foundation,whichisgovernedandrunindependentlyof Microsoft.C#language specifications,compilers,andrelatedtoolsare opensource projectsonGitHub.While C#language feature designis ledbyMicrosoft, the opensource communityisveryactive inthe language developmentandimprovements. C# is fastcompare to several otherhigh-level programminglanguages.C#8 has manyperformance improvements. C# is cross platform
  • 4. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 5 C# is cross platformprogramming language.Youcan build.NETapplicationsthatcanbe deployedonWindows, Linux,andMac platforms.C#apps can alsobe deployedincloudandcontainers. C# is safe and efficient C# is a type safe language.C#doesnot allowtype conversionsthatmay leadto data lossor otherproblems.C# allowsdeveloperstowrite safe code.C#alsofocusesonwritingefficientcode. Here is a listof some of the keyconceptsinC# that helpswrite safe andefficientcode. Unsafe type castingisnot allowed. Nullable andnon-null abletypesare supportedinC#. Declare a readonlystructto expressthata type isimmutable andenablesthe compilertosave copieswhenusingin parameters. Use a ref readonlyreturnwhenthe returnvalue isa structlarger thanIntPtr.Size andthe storage lifetime isgreater than the methodreturningthe value. Whenthe size of a readonlystructisbiggerthanIntPtr.Size,youshouldpassitasan in parameterforperformance reasons. Neverpassa struct as an inparameterunlessitis declaredwiththe readonlymodifierbecauseitmaynegatively affectperformance andcouldleadtoan obscure behavior. Use a ref struct, or a readonlyref structsuch as Span<T> or ReadOnlySpan<T>towork withmemoryasa sequence of bytes. C# is versatile C# is a Swissarmyknife.While mostprogramminglanguagesweredesignedforaspecificpurpose,C#wasdesigned to do C#. We can use C# to buildtoday’smodernsoftware applications.C#can be usedto developall kindof applicationsincludingWindows clientapps,componentsandlibraries,servicesandAPIs,Webapplications,Mobile apps,cloudapplications,andvideogames. Here is a listof typesof applicationsC#can build: Windowsclientapplications Windowslibrariesandcomponents Windowsservices Webapplications WebservicesandWebAPI
  • 5. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 6 Native iOSandAndroidmobile apps Backendservices Azure cloudapplicationsandservices Backenddatabase usingML/Data tools InteroperabilitysoftwaresuchasOffice,SharePoint,SQLServerandsoon. Artificial IntelligenceandMachine learning Blockchainsand distributedledgertechnologyincludingcryptocurrency Internetof Things(IoT) devices Gamingconsolesandgamingsystems Videogames C# History History of C# language isinterestingtoknow.Here we are goingto discussbrief historyof C#language.C#is pronouncedas "C-Sharp".Itis an object-orientedprogramminglanguage providedby Microsoftthatruns on .Net Framework. AndersHejlsbergisknownas the founderof C# language. It isbasedon C++ and Java, but ithas many additional extensionsusedtoperformcomponentoriented programmingapproach. C# has evolvedmuchsince theirfirstrelease inthe year 2002. It was introducedwith .NETFramework 1.0 and the currentversionof C# is 10.0. C# Version History C# was first introduced with .NET Framework 1.0 in the year 2002 and evolved much since then. The following table lists important features introduced in each version of C#:
  • 6. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 7 Version .NET Framework Visual Studio Important Features C# 1.0 .NET Framework 1.0/1.1 Visual Studio .NET 2002 Basic features C# 2.0 .NET Framework 2.0 Visual Studio 2005 Generics Partial types Anonymous methods Iterators Nullable types Private setters (properties) Method group conversions (delegates) Covariance and Contra-variance Static classes C# 3.0 .NET Framework 3.03.5 Visual Studio 2008 Implicitly typed local variables Object and collection initializers Auto-Implemented properties Anonymous types Extension methods Query expressions Lambda expressions Expression trees Partial Methods C# 4.0 .NET Framework 4.0 Visual Studio 2010 Dynamic binding (late binding) Named and optional arguments Generic co- and contra variance Embedded interop types C# 5.0 .NET Framework 4.5 Visual Studio 2012/2013 A sync features Caller information
  • 7. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 8 Version .NET Framework Visual Studio Important Features C# 6.0 .NET Framework 4.6 Visual Studio 2013/2015 Expression Bodied Methods Auto-property initializer name of Expression Primary constructor Await in catch block Exception Filter String Interpolation C# 7.0 .NET Core 2.0 Visual Studio 2017 out variables Tuples Discards Pattern Matching Local functions Generalized a sync return types C# 8.0 .NET Core 3.0 Visual Studio 2019 Read-only members Default interface methods Using declarations Static local functions Disposable ref structs Nullable reference types More C# 9.0 .NET 5.0 Visual Studio 2019 Records Init-only properties Top-level statements Init accessors and readonly fields With-expressions Value-based equality more
  • 8. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 9 Version .NET Framework Visual Studio Important Features C# 10.0 .NET 6.0 Visual Studio 2022 Record structs Global using directives File-scoped namespace declaration Extended Proptery Patterns Null Parameter Checking Constant interpolated strings more C# Example:HelloWorld In C# programming language, a simple "hello world" program can be written by multiple ways. Let us see the top four ways to create a simple C# example: Simple Example Using System Using public modifier Using namespace C# Simple Example class Program { static void Main(string[] args) { System.Console.WriteLine("Hello World!"); } } Output: Hello World! Description class: is a keyword, which is used to define class. Program: is the class name. A class is a blueprint or template from which objects are created. It can have data members and methods. Here,it has only Main method.’ static: is a keyword that means object is not required to access static members. So it saves memory. void: is the return type of the method. It does't return any value. In such case,return statement is not required.
  • 9. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 10 Main: is the method name. It is the entry point for any C# program. Whenever we run the C# program, Main() method is invoked first before any other method. It represents start up of the program. string[] args: is used for command line arguments in C#. While running the C# program, we can pass values. These values are known as arguments which we can use in the program. System.Console.WriteLine("Hello World!"): Here,System is the namespace. Console is the class defined in System namespace. The WriteLine() is the static method of Console class which is used to write the text on the console. C# Example: Using System If we write using Systembefore the class,it means we don't need to specify System namespace for accessing any class of this namespace. Here,we are using Console class without specifying System.Console. using System; class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } Output: Hello World! C# Example: Using public modifier We can also specify public modifier before class and Main() method. Now, it can be accessed from outside the class also. using System; public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } Output:
  • 10. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 11 Hello World! C# Example: Using namespace We can create classes inside the namespace. It is used to group related classes. It is used to categorize classes so that it can be easy to maintain. using System; namespace ConsoleApplication1 { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } Output: C# Program Structure A typical C# Program consists ofseveral different parts as shown below: Namespace Class The main method Methods inside the class Class definition or class attributes Statements Comments Few things need to be kept in mind while writing a C# program. C# programs are case sensitive, which means “string” is different from “String”. All the statements written in the program must be concluded with a semicolon i.e. “;”. A semicolon tells the program that the current line of the statement has ended. Hello World!
  • 11. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 12 As discussed earlier, the execution of the C# program starts from the Main method, hence the program should have the Main method as its starting point. Before we begin with an explanation ofthe C# components lets recall a fewpoints: A program needs to have a reference to the .Net framework that has been used in the program. For our current program to reference.Net,we use “using”. For Example “using System” in our above program. After defining the references we declare a namespace. Syntax Example- namespace ConsoleApplication. Then we declared a class using a class keyword. Syntax Example- class Program. Inside the class, we have a Main method. This is the starting point of the execution. Inside the Main method, we have defined “Console” which is a class in the .Net framework. The “WriteLine()” is a method that is used to display a message in a console. Similar to “WriteLine()”, “ReadLine()” is also a method that reads user input. In the above program, we wrote a text in the console application and discussed various parts of the program. Here, we will discuss various parts that were used in conjuncture with each other to make-up a valid syntax in detail. We will discuss components, their definition and ways in which we have to declare them in the program. Using Keyword The using keyword is used to handle any object that is being used to implement the namespace. It is used to import a namespace. As a namespace is a collection of classes and each class has its own functionality, so using the keyword provides us with the facility to implement different functionality from the namespace that has been imported. Namespace The namespace is a collection of related classes and objects. It is designed to offer a way to keep a different set of objects segregated from each other. This allows the programmers to declare one class inside a namespace and another class inside another namespace without causing a conflict. Let us say we are creating two namespaces namely “fruits” and “colors”. Both these namespaces can have a class called “Orange” without creating any conflict with each other. A namespace is defined by writing your namespace name preceded by keyword namespace. For Example: namespace ConsoleApplication Class Defining a class is similar to defining a blueprint of a data type. Class does not actually define the data but they arrange the data as a meaningful entity. For Example,if we have a class called “Fruit”, and then we can specify different related objects inside the class such as mango, apple, grapes, etc. Thus, the class fruit will contain different fruit objects with different properties such as color, taste, smell, edible, etc. Each of these objects and property will be a part of the class. Similar to the above example, the object-oriented programming language such as C# also defines different properties inside i.e. fields, methods, conditions, events, etc. The objects inside the class contain a definition of the operations that can be performed. Objects are an instance of the class and the methods or the variables that are the members of the class. Thus, in short, the class allows you to create your own custom objects by grouping other methods, events and object types. A class is defined by putting the keyword “class” before the name of the class and a pair of curly braces should define the class body.
  • 12. Department of Information Technology Event-Driven Programming C# ETHIOPIAN POLICEUNIVERSITY Page | 13 class Program { // class body } Access Modifiers Access modifiers define the accessibility of an object and its components. All the C# components have their own access levelthat can be controlled by defining the scope of accessibility for the member objects inside the class by using access modifiers. To define the accessibility level of the object we have to declare it by using one of the keywords provided by C# language i.e. Public, Private, Protected and Internal. Access modifier is declared by using of the keywords mentioned above either before the class or a method.
  • 13. Departmentof InformationTechnology Event-DrivenProgrammingC# ETHIOPIAN POLICEUNIVERSITY These arguments are useful while calling a method with certain parameters. In the above example, we have passed only one parameter that is “args” with the argument type as an array of string. Constructor Constructors are the special methods in a class that is automatically invoked whenever an instance of the particular class is created. The main advantage of the constructor is that it can initialize the private fields of a class. A class can have a number of constructors and it does not need to have any return type. Only one static constructor is allowed inside a class and that cannot be parameterized. Constructors are declared by using any access modifier and then by using the class name in which it is created. For Example, a constructor definition will look something like this. class Program { public class(){ //This is a constructor } } Data types are used in almost all the programming languages. A data type tells the compiler what kind of value a variable will hold. C# has several built-in data types such as String, Integer, Float, Boolean, etc. Each data type has its own set of definitions for the values it can hold. A data type is used to declare a variable by the preceding variable with the data type keyword. class Program { static void Main(string[]args) { string stringValue = "Hello"; int integerValue = 10;float floatValue = 13.2f; bool booleanValue = false; } } Curly Braces We saw the extensive usage of curly braces “{}” in our previous programs and declarations which is why it is referred to as one of the most important parts of any program. It defines the beginning and the end of any logical statement in a program block.
  • 14. Departmentof InformationTechnology Event-DrivenProgrammingC# ETHIOPIAN POLICEUNIVERSITY The curly braces are not only restricted to the C# language, but they are also found in several other languages like Java,C++, etc. You can clearly see our first “Hello World” code that they are used to wrap multiple lines of code together. It clearly marks the starting and the endpoint of the logical statement for the compiler. Any logical entity like Namespace,Class,Method, Conditional statement, Loops, etc. should be enclosed inside braces to clearly mark the start and end of the statement for the compiler.