table of contentsenvironmentclearance.nic.in/writereaddata/online/... · multiplatform and with...
TRANSCRIPT
1.1
1.2
1.3
1.4
1.5
TableofContentsIntroduction
Outline
DesignPattern
VisualStudio
Basics
2
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
Introduction
4
AbriefsummaryoftheprogramminglanguageofMicrosotftcalledC#or.Net.
Thereisnoguaranteethatthisreferenceiscompleteorcorrect.Ifyouwanttocontributeorreportinganissue:
RepoIssue
ContributorandReferencesC#GuideOfficialMicrosoftReferenceTutorialADP.NetUMLClassDiagramInversionofControlDesignPattern
ThanksThanksgoesto:
Outline
5
MicrosoftAllcontributors
Outline
6
DesignPattern
CreationalPatterns
DesignPattern
7
Pattern Description Image
AbstractFactory
Createsaninstanceofseveralfamiliesofclasses
Builder Separatesobjectconstructionfromitsrepresentation
FactoryMethod
Createsaninstanceofseveralderivedclasses
Prototype Afullyinitializedinstancetobecopiedorcloned
Singleton Aclassofwhichonlyasingleinstancecanexist
StructuralPatterns
Pattern Description Image
DesignPattern
8
Adapter Matchinterfacesofdifferentclasses
Bridge Separatesanobject’sinterfacefromitsimplementation
Composite Atreestructureofsimpleandcompositeobjects
Decorator Addresponsibilitiestoobjectsdynamically
Facade Asingleclassthatrepresentsanentiresubsystem
DesignPattern
9
Flyweight Afine-grainedinstanceusedforefficientsharing
Proxy Anobjectrepresentinganotherobject
BehavioralPatterns
Pattern Description Image
ChainofResp.
Awayofpassingarequestbetweenachainofobjects
Command Encapsulateacommandrequestasanobject
Interpreter Awaytoincludelanguageelementsinaprogram
DesignPattern
10
Iterator Sequentiallyaccesstheelementsofacollection
MediatorDefinessimplifiedcommunicationbetweenclasses
Memento Captureandrestoreanobject'sinternalstate
Observer Awayofnotifyingchangetoanumberofclasses
State Alteranobject'sbehaviorwhenitsstatechanges
Strategy Encapsulatesanalgorithminsideaclass
DesignPattern
11
TemplateMethod
Defertheexactstepsofanalgorithmtoasubclass
Visitor Definesanewoperationtoaclasswithoutchange
DesignPattern
12
VisualStudioTheVisualStudiointegrateddevelopmentenvironment(IDE)isacollectionofdevelopmenttoolsexposedthroughacommonuserinterface.SomeofthetoolsaresharedwithotherVisualStudiolanguages,andsome,suchastheC#compiler,areuniquetoVisualC#.
SolutionsInVisualStudioonlysolutionscanbeused.Eachproject(akasolution)needtohaveallnecessaryfiletobebuildandopenendinVisualStudio.
AnewProject/SolutioncanbecreatedatFile=>New=>Project
VisualStudio
13
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
VisualStudio
15
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
Type Description
Dependencies Listofallneededdependenciesandthirdpartylibrariesfortheprogram
Program.csMainprogramC#file,oneneedstocontaintheMainmethodasentrypointoftheprogram.
VisualStudio
17
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
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
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
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
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
Anotherexampletoshowhowyoucanpreventdividingbyzerofromresultingininfinity:
letx=1
lety=x&/0//Divisionbyzeroy=0
OtherOperators
Operator Purpose
?? Nilcoalescing(takeleftifnotnilelserightvalue)
?: Ternaryconditional
! Forceunwrapobjectvalue
? Safelyunwrapobjectvalue
Basics
23