table of contentsenvironmentclearance.nic.in/writereaddata/online/... · multiplatform and with...

23

Upload: others

Post on 31-Dec-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,
Page 2: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

1.1

1.2

1.3

1.4

1.5

TableofContentsIntroduction

Outline

DesignPattern

VisualStudio

Basics

2

Page 3: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

C#CheatSheetbytschinzThisisaattempttocreateasmalleasy-to-understandaswellaseasy-to-usecheatsheetforC#.C#istheprogramminglanguageofMicrosoftusedinalloftheirdevices.ItismultiplatformandwithhelpofXamarinitcanbedeployedonavarietyofdevices.C#isageneral-purpose,type-safe,object-orientedprogramminglanguage.Thegoalofthelanguageisprogrammerproductivity.Tothisend,thelanguagebalancessimplicity,expressiveness,andperformance.TheC#languageisplatform-neutral,butitwaswrittentoworkwellwiththeMicrosoft.NETFramework.C#6.0targets.NETFramework4.6.

License

SwiftCheatSheetbytschinzislicensedunderaCreativeCommonsAttribution-NonCommercial-NoDerivatives4.0InternationalLicense.

Changelog

v0.0.1-TBD

Introduction

3

Page 4: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Introduction

4

Page 5: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

AbriefsummaryoftheprogramminglanguageofMicrosotftcalledC#or.Net.

Thereisnoguaranteethatthisreferenceiscompleteorcorrect.Ifyouwanttocontributeorreportinganissue:

RepoIssue

ContributorandReferencesC#GuideOfficialMicrosoftReferenceTutorialADP.NetUMLClassDiagramInversionofControlDesignPattern

ThanksThanksgoesto:

Outline

5

Page 6: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

MicrosoftAllcontributors

Outline

6

Page 7: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

DesignPattern

CreationalPatterns

DesignPattern

7

Page 8: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Pattern Description Image

AbstractFactory

Createsaninstanceofseveralfamiliesofclasses

Builder Separatesobjectconstructionfromitsrepresentation

FactoryMethod

Createsaninstanceofseveralderivedclasses

Prototype Afullyinitializedinstancetobecopiedorcloned

Singleton Aclassofwhichonlyasingleinstancecanexist

StructuralPatterns

Pattern Description Image

DesignPattern

8

Page 9: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Adapter Matchinterfacesofdifferentclasses

Bridge Separatesanobject’sinterfacefromitsimplementation

Composite Atreestructureofsimpleandcompositeobjects

Decorator Addresponsibilitiestoobjectsdynamically

Facade Asingleclassthatrepresentsanentiresubsystem

DesignPattern

9

Page 10: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Flyweight Afine-grainedinstanceusedforefficientsharing

Proxy Anobjectrepresentinganotherobject

BehavioralPatterns

Pattern Description Image

ChainofResp.

Awayofpassingarequestbetweenachainofobjects

Command Encapsulateacommandrequestasanobject

Interpreter Awaytoincludelanguageelementsinaprogram

DesignPattern

10

Page 11: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Iterator Sequentiallyaccesstheelementsofacollection

MediatorDefinessimplifiedcommunicationbetweenclasses

Memento Captureandrestoreanobject'sinternalstate

Observer Awayofnotifyingchangetoanumberofclasses

State Alteranobject'sbehaviorwhenitsstatechanges

Strategy Encapsulatesanalgorithminsideaclass

DesignPattern

11

Page 13: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

VisualStudioTheVisualStudiointegrateddevelopmentenvironment(IDE)isacollectionofdevelopmenttoolsexposedthroughacommonuserinterface.SomeofthetoolsaresharedwithotherVisualStudiolanguages,andsome,suchastheC#compiler,areuniquetoVisualC#.

SolutionsInVisualStudioonlysolutionscanbeused.Eachproject(akasolution)needtohaveallnecessaryfiletobebuildandopenendinVisualStudio.

AnewProject/SolutioncanbecreatedatFile=>New=>Project

VisualStudio

13

Page 14: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

ProjectType Description Solutionimage

BlankApp(UniversalWindows)

Aprojectforasingle-pageUniversalWindowsPlatform(UWP)appthathasnopredefinedcontrolsorlayout.Bestifyouknowwhatyou'redoing.

WPFApp(.NETFramework)

Classicgraphicaldesktopapplicationbasedonthe.NETFramework.AlsocalledWindowsPresentationFoundationclientapplication.

ConsoleApp(.NETCore)

NewConsoleappbasedonthe.NETCore.Aprojectforcreatingacommand-lineapplicationthatcanrunonWindows,Linux,MacOS.(Doesn'tcreatesanexefile).

ConsoleApp(.NETFramework)|Aprojectforcreatingacommand-lineapplication.ThiswillonlyworkonWindowsandwillcreateanexedirectly.

OneSolutioncancontainmanyProjects

WPFAppAWPFAppalreadyhasapredefinedstructure

VisualStudio

14

Page 15: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

VisualStudio

15

Page 16: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Type Element Description

Properties AssemblyInfo.cs

AssemblyInfo.cscontainsinformationaboutyourassembly,likename,description,version,etc.Ifyoudeleteit,yourassemblywillbecompiledwithnoinformation.

Properties ResourcesThisisadatabaselikestructureforstoringresourcesneededintheprogram.ThiscanbeFiles,Images,StringValues,TextFiles.

Properties Settings

Applicationsettingsallowyoutostoreandretrievepropertysettingsandotherinformationforyourapplicationdynamically.

References

ContainsallnecessarynamespacesandthirdpartylibrariesusedintheApplication.ItisbettertouseNuGetpackagesfoundintheProjectsettings.

App.config

isanXMLfilewithmanypredefinedconfigurationsectionsavailableandsupportforcustomconfigurationsections.A"configurationsection"isasnippetofXMLwithaschemameanttostoresometypeofinformation.

App.xamlApp.xamlalsocontainsa.csfile.Thisisthemainentrypointlaunchingthegui.

MainWindow.xaml

MainWindow.xamlalsocontainsa.csfile.EachofthesefilesrepresentapartoftheGUI.

IntheProjectSettingsallaboveelementscanbesetinonesinglelocation

ConsoleApp(.NETCore)

VisualStudio

16

Page 17: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Type Description

Dependencies Listofallneededdependenciesandthirdpartylibrariesfortheprogram

Program.csMainprogramC#file,oneneedstocontaintheMainmethodasentrypointoftheprogram.

VisualStudio

17

Page 18: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

ProgrammingBasics

Comments

//Thisisacomment

/*Thisisamultilinecomment

Theycannotbenbested!*/

CommentLinks

//MARK:TestappearsinXcodeselector

//TODO:Writeyourtodohere

//FIXME:Writeyourbughere(orfixisdirectly)

Importingnamespaces

usingSystem;//importnamespaceSystem

Console.WriteLine(x);//usefunctionofnamespaceSystem

System.Console.WriteLine(x);//usingwithoutimportinnamespace

TypesForacompleteguideto64-bitchanges,pleaseseethetransitiondocument.

DefaultSwiftTypes

Basics

18

Page 19: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

SwiftType Values

IntInt32,Int64,UInt8,UInt16

100Dezimal1_000_000Dezimal0b1001Binary0o85Octal0xFFE3Hexadezimal

Double3.14159265

3.141_592_65

1.25e2=125.0

1.25e-2==0.0125

Bool true

false

String "ThisisaString"

"ThisisaStringincludinga\(varname)"

C-TypesvsSwiftTypes

CType SwiftType

bool CBool

char,signedchar CChar

unsignedchar CUnsignedChar

short CShort

unsignedshort CUnsignedShort

int CInt

unsignedint CUnsignedInt

long CLong

unsignedlong CUnsignedLong

longlong CLongLong

unsignedlonglong CUnsignedLongLong

wchar_t CWideChar

char16_t CChar16

vchar32_t CChar32

float CFloat

double CDouble

Fromthedocs

Basics

19

Page 20: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

OperatorsSwiftsupportsmoststandardCoperatorsandimprovesseveralcapabilitiestoeliminatecommoncodingerrors.

Arithmeticoperators(+,-,*,/,%andsoforth)detectanddisallowvalueoverflow,toavoidunexpectedresultswhenworkingwithnumbersthatbecomelargerorsmallerthantheallowedvaluerangeofthetypethatstoresthem.

ArithmeticOperators

Operator Purpose

+ Addition

- Subtraction

* Multiplication

/ Division

% Remainderalsoworksonfloat8%2.5//equals0.5

ComparativeOperators

Operator Purpose

== Equalto

=== Identicalto

!= Notequalto

!== Notidenticalto

~= Patternmatch

> Greaterthan

< Lessthan

>= Greaterthanorequalto

<= Lessthanorequalto

AssignmentOperators

Basics

20

Page 21: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Operator Purpose

= Assign

+= Addition

-= Subtraction

*= Multiplication

/= Division

%= Remainder

&= BitwiseAND

|= BitwiseInclusiveOR

^= ExclusiveOR

<<= ShiftLeft

>>= ShiftRight

&&= LogicalAND

||= LogicalOR

IncrementandDecrementOperators

Operator Purpose

++ Addition

-- Subtraction

++x//incrementsvariable**before**returningit'svalue

x--//incrementsvariable**after**returningit'svalue

LogicalOperators

Operator Purpose

! NOT

&& LogicalAND

|| LogicalOR

RangeOperators

Basics

21

Page 22: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Operator Purpose

..< Half-openrange

... Closedrange

forindexin1..<3{}//1to3excluding3

forindexin1...3{}//1to3inluding3

BitwiseOperators

Operator Purpose

& BitwiseAND

| BitwiseInclusiveOR

^ ExclusiveOR

~ Unarycomplement(bitinversion)

<< ShiftLeft

>> ShiftRight

OverflowandUnderflowOperators

Typically,assigningorincrementaninteger,float,ordoublepastit'srangewouldresultinarun-timeerror.However,ifyou'dinsteadprefertosafelytruncatethenumberofavailablebits,youcanopt-intohavethevariableoverfloworunderflowusingthefollowingoperators:

Operator Purpose

&+ Addition

&- Subtraction

&* Multiplication

&/ Division

&% Remainder

Exampleforunsignedintegers(workssimilarlyforsigned):

varwillOverflow=UInt8.max//willOverflow=255

willOverflow=willOverflow&+1//willOverflow=0

varwillUnderflow=UInt8.min//willUnderflow=0

willUnderflow=willUnderflow&-1//willUnderflow=255

Basics

22

Page 23: Table of Contentsenvironmentclearance.nic.in/writereaddata/Online/... · multiplatform and with help of Xamarin it can be deployed on a variety of devices. C# is a general-purpose,

Anotherexampletoshowhowyoucanpreventdividingbyzerofromresultingininfinity:

letx=1

lety=x&/0//Divisionbyzeroy=0

OtherOperators

Operator Purpose

?? Nilcoalescing(takeleftifnotnilelserightvalue)

?: Ternaryconditional

! Forceunwrapobjectvalue

? Safelyunwrapobjectvalue

Basics

23