![Page 1: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/1.jpg)
ITF11006 .NET
The Basics
![Page 2: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/2.jpg)
The Basics• Data Types
– Value Types– Reference Types
• Flow Control– Conditional– Loop
• Miscellaneous– Enumerations– Namespaces
• Class / Struct– Data Members– Functional Mem
• Base Classes– System.Object– System.String
![Page 3: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/3.jpg)
Variables/Constants
• Syntax[modifier] type identifier [= expression];
• Scope
– Class/Block
• Constants[modifier] const type identifier [= constant-expression];
• Type Inferencevar identifier [= expression];
![Page 4: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/4.jpg)
Predefined Data Types
• Value Types
• Reference Types
![Page 5: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/5.jpg)
Predefined Data Types
• Value Types
– Integer Types
– Floating Point Types
– Decimal Type
– Boolean Type
– Character Type
![Page 6: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/6.jpg)
Integer Types
C# data type Description Class name Range
sbyte A 8-bit signed integer. System.SByte -128:127
short A 16-bit signed integer. System.Int16 -32.768: 32.767
int A 32-bit signed integer. System.Int32 -2.147.483.648: 2.147.483.647
long A 64-bit signed integer. System.Int64 -9.223.372.036.854.775.808: 9.223.372.036.854.775.807
byte An 8-bit unsigned integer. System.Byte 0:255
ushort A 16-bit unsigned integer. System.UInt16 0:65535
uint A 32-bit unsigned integer. System.UInt32 0:4.294.967.295
ulong A 64-bit unsigned integer. System.UInt64 0:18.446.744.073.709.551.615
![Page 7: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/7.jpg)
Floating Point
C# data type Description Class name Significant fig. Range
float A single-precision (32-bit) floating-point number.
System.Single 7 +1.5x10-45 to +3.4x1038
double A double-precision (64-bit) floating-point number.
System.Double 15/16 +5.0x10-324 to +1.7x10308
![Page 8: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/8.jpg)
Decimal Type
C# data type Description Class name Significant fig. Range
decimal A 96-bit decimal value.(128 bit space!)
System.Decimal 28 +1.0x10-28 to +7.9x1028
![Page 9: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/9.jpg)
Boolean Type
C# data type Description Class name Range
bool Logical true or false System.Boolean true or false
![Page 10: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/10.jpg)
Character TypeC# data type Description Class name
char 16 bits. Represents a single (Unicode) character System.Char
![Page 11: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/11.jpg)
Nullable Types (http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=VS.100).aspx)
• T? orSystem.Nullable(Of T)
• Ordinary type plus null
![Page 12: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/12.jpg)
Predefined Reference Types
• Object• String
![Page 13: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/13.jpg)
Flow Control• Conditional
– if– switch
• Loop– for– while– do..while– foreach
• Jump– goto– break– continue– return
![Page 14: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/14.jpg)
Conditional Statements
• if if (expression) statement1 [else statement2]
• switch switch (expression){
case constant-expression:
statement
jump-statement
[default:
statement
jump-statement]
}
![Page 15: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/15.jpg)
Loops
• for for ([initializers]; [expression]; [iterators]) statement
• while while (expression) statement
• do..while do statement while (expression);
• foreach foreach (type identifier in expression) statement
![Page 16: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/16.jpg)
Jump Statements
• goto• break• continue• return• (throw)
![Page 17: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/17.jpg)
Enumerations
• enum[modifiers] enum identifier [:base-type]
{enumerator-list} • Inherits from System.Enum• Flags Attribute• Use enumerations
![Page 18: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/18.jpg)
Namespaces
• Logical grouping of functionality• <company>.<technology/sw package>• Using directive
![Page 19: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/19.jpg)
Class (/Struct)
• Data Members– Fields– Constants– Events
• Function Members– Methods– Properties– Constructor– Destructor– Operators– Indexers
![Page 20: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/20.jpg)
Methods
• syntax[modifiers] return-type method-name([formal-parameter-list]) { statement(s)}
• Named Argumentsstring FullName(string firstName, string lastName)…
FullName(“Ole”, “Olsen”);FullName(lastName: “Olsen”, firstName: “Ole”);
• Optional Arguments
• Method Overloading
![Page 21: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/21.jpg)
Properties
• syntax[modifiers] type identifier {
set {accessor-body} get {accessor-body}
}
• Auto-Implementedpublic string Age(get; private set;)
• Choosing Between Properties and Methodshttp://msdn.microsoft.com/en-us/library/ms229054.aspx
![Page 22: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/22.jpg)
Construction and Disposal
• Constructors– Instance– Class– Calling
• Destructor– Why– How (pattern)
• Dispose vs. Close
![Page 23: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/23.jpg)
Operators
• Operator Overloading
public static Vector operator * (double lhs, Vector rhs)
{
return new Vector(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
}
public static Vector operator * (Vector lhs, double rhs)
{
return rhs * lhs;
}
Console.WriteLine("vect2 * 2 = " + ( vect2 * 2).ToString());
![Page 24: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/24.jpg)
Indexerspublic char this[int index]
{
get
{
...
}
set
{
...
}
}
![Page 25: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/25.jpg)
Instance vs. Class Level
• Static• this vs. class name
![Page 26: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/26.jpg)
Struct
• No inheritance (almost)• Constructors• Fields are sometimes declared public!• Structs are value types
![Page 27: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/27.jpg)
Struct vs. class
• Footprint• Performance
![Page 28: ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class](https://reader031.vdocument.in/reader031/viewer/2022032200/56649f535503460f94c77218/html5/thumbnails/28.jpg)
object (System.Object)
• Methods
• Comparing for Equality– Reference Types– Value Types
Method Access
string ToString() public virtual
int GetHashCode() public virtual
bool Equals(object obj) public virtual
bool Equals(object objA, object objB) public static
bool ReferenceEquals(object objA, object objB) public static
Type GetType() public
object MemberwiseClone() protected
void Finalize() protected virtual