Post on 14-Dec-2015
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
.NET Basic Fundamentals
Presented By :
Muhammad Atif HussainDeputy Manager IT (Takaful Pakistan Limited)Technologies Consultant (AUC Technologies)
MCS(KU)MSCS(SZABIST)MCPMCADMCSDMCTS (Windows, Web, Distributed Applications)MCPD (Enterprise Applications)MCT(Microsoft Certified Trainer)
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Overview of .NET Languages• DataTypes• Primitive Data Types• Type Casting• Arrays• Multidimensional Arrays• Basic Access Modifiers• Abstract Data Types• Variables• Properties/Attributes• Functions/Methods/Procedures• OverLoading
Agenda•Constructors•Inheritance•Constructor Chaining•Conditional Statememt•Loops•Namespaces•Struct•Enumerators•Delegates•Events
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• .NET languages provided by Microsoft– C++– Visual Basic– C#– J#– F# (2010)
• Over 30 .NET-compatible languages– Most are provided by 3rd parties
.NET Languages
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Ada• APL• Basic (Visual Basic)• C#• C• C++• Java Language• COBOL• Component Pascal
(Queensland Univ of Tech)• ECMAScript (JScript)• Eiffel (Monash University)• Haskell
(Utrecht University)
• lcc (MS Research Redmond)
• Mondrian (Utrecht)• ML
(MS Research Cambridge)• Mercury
(Melbourne U.) • Oberon
(Zurich University)• Oz (Univ of Saarlandes)• Perl• Python• Scheme
(Northwestern U.)• SmallTalk
3rd Party Language Compiler List
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
TypeType SizeSizeboolbool 11sbytesbyte 11bytebyte 11shortshort 22ushortushort 22intint 44uintuint 44
TypeType SizeSizelonglong 88ulongulong 88charchar 22floatfloat 44doubledouble 88decimaldecimal 1616stringstring 20+20+
Primitive types
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• All Primitive types are objects• Primitive Types are FCL Types
– Aliases the primitives– Example: Int32 == int (C#)– Example: Int32 == Integer
Primitive types
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
Primitive typesC#C# VBVB SizeSize MinimumMinimum MaximumMaximum
sbytesbyte SbyteSbyte 11 -127-127 128128
bytebyte ByteByte 11 00 255255
shortshort ShortShort 22 -32768-32768 3276732767
ushortushort UShortUShort 22 00 6553565535
intint IntegerInteger 44 -2147483648-2147483648 21474836472147483647
uintuint UIntegerUInteger 44 00 42949672954294967295
longlong LongLong 88 -9223372036854775808-9223372036854775808 92233720368547758079223372036854775807
ulongulong ULongULong 88 00 1844674407370955161518446744073709551615
doubledouble DoubleDouble 88 -1.79769313486232E+308-1.79769313486232E+308 1.79769313486232E+3081.79769313486232E+308
decimaldecimal DecimalDecimal 1616 -79228162514264337593543950335-79228162514264337593543950335 7922816251426433759354395033579228162514264337593543950335
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Move data of one data type to another
Type Casting
LongLong
IntegerInteger
ShortShort
ByteByte
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• No loss of data
Byte b = 1Short s = bInteger i = sLong l = i
Implicit Type Casting
byte b = 1;short s = b;int i = s;long l = I;
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Possible loss of precision
Explicit Type Casting
Short s = 256Byte b = s
short s = 256;byte b = s;
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Collection of similar type of Object
• Arrays are objects too!– ages.Length– ages.Clone()
Arrays
int[] x = new int[10];int[] x = { 5, 8, 39 };
Dim x(10) As IntegerDim x() As Integer = {5, 8, 39}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
Rectangular
Jagged
Multidimensional Arrays
int[,] x = new int[ 8, 8 ];Dim x(10, 10) As Integer
int[][] x= new int[2][];x[0] = new int[ 4 ];x[1] = new int[ 3 ];
Dim x(,) As Integerx(0, 0) = 1x(1, 0) = 2x(1, 1) = 3
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• User define data type
Abstract Data Type
Public Class Student
End Class
public class Student{}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
Basic Access Modifiers
FormForm MeaningMeaningpublic public Access not limited. Access not limited. private private Access limited to the containing type. Access limited to the containing type.
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Variables• Properties• Functions (Methods/Procedure/Sub Routine)• Constructors
Basic Members of Abstract Data Type
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Specific type
• Hold data temporarily for reuse
• Instance Variable / Local Variable
Variables
Short s = 256Byte b = 100
short s = 256;byte b = 100;
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Get and Set
• Guard instance variables
• Read Only, Write Only and Both
Properties
Public Property Age() As Integer Get Return _age End Get Set(ByVal value As Integer) _age = value End Set End Property
class Person { private int _age; public int Age { get { return _age; } set { _age = value; } }}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Set of Instructions• Function must return a value
• Function don’t return a value
Functions
Public Function Add(ByVal i As Integer, ByVal j As Integer) As Long Return i + jEnd Function
public long Add(int i, int j) { return i + j;}
Public Sub Print() Console.WriteLine("Name")End Sub
public void Print() { Console.WriteLine("Name"); }
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Number of Argument / Parameter
• Type of Argument / Parameter
• Arrangement of Argument / Parameter
Functions Signature
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Same name of functions with different Signatures
Functions Overloading
Public Function Add(ByVal i As Integer, ByVal j As Integer) As Long Return i + jEnd Function Public Function Add(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer) As Long Return i + j + kEnd Function
public long Add(int i, int j) { return i + j; }
public long Add(int i, int j, int k) { return i + j + k; }
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Special type of functions• Called once in the life of instance• Initiate the instance of class in memory• Initialize instance variable with their default values
Constructors
Public Class Person Sub New() End SubEnd Class
class MyClass
{
public MyClass() { }
}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Same name of Constructor with different Signatures
Constructor Overloading
Public Function Add(ByVal i As Integer, ByVal j As Integer) As Long Return i + jEnd Function Public Function Add(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer) As Long Return i + j + kEnd Function
public long Add(int i, int j) { return i + j; }
public long Add(int i, int j, int k) { return i + j + k; }
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Classes can extend / inherit one class at a time
Inheritance
ManMan WomanWoman
HumanHuman
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Generalize common functionalities to base class
Generalization
Public Class HumanPublic Function Eat()End Function
End Class
Public Class ManInherits Human
End Class
Public Class WomanInherits Human
End Class
public class Human {
public void Eat(){}
}
public class Man : Human { }
public class Woman : Human { }
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Specialized specific functionalities to child class
Specialization
Public Class HumanEnd ClassPublic Class Man
Inherits HumanPublic Function Work()End Function
End Class
Public Class WomanInherits HumanPublic Function Talk()End Function
End Class
public class Human {}
public class Man : Human {public void Work(){}
}
public class Woman : Human { public void Talk(){}
}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Extend base class functionalities in child class
Overriding (Virtual / Overridable)
Public Class Human Public Overridable Sub Sleep() End SubEnd Class
Public Class Woman Inherits Human Public Overrides Sub Sleep() End SubEnd Class
public class Human{ public virtual void Sleep() { }}public class Woman : Human { public overrides void Sleep() { }}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Extend base class abstract functionalities in child class• Whole class will become abstract / MustInherit if contain any abstract / MustOverride function
Overriding (Abstract / MustOverride)
Public MustInherit Class Human Public MustOverride Sub Eat()End Class
Public Class Woman Inherits Human Public Overrides Sub Eat() End SubEnd Class
public abstract class Human{ public abstract void Eat();}public class Woman : Human { public overrides void Eat() { }}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Shadowing base class functionalities in child class
Shadowing
Public Class Human Public Sub Walk() End SubEnd Class
Public Class Woman Inherits Human Public Shadows Sub Walk() End SubEnd Class
public class Human{ public void Walk();}public class Woman : Human { public new void Walk() { }}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Lock more Inheritance
Sealed / NotInheritable Class
Public Class HumanEnd Class
Public NotInheritable Class Woman Inherits HumanEnd Class
public class Human{ public void Walk();}public sealed class Woman : Human { public new void Walk() { }}
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Every constructor calls its base class constructor first
• All types ultimately inherit from object
– Classes, enums, arrays, delegates, structs, …
Constructor Chaining
StreamStream
MemoryStreamMemoryStream FileStreamFileStream
HashTableHashTable doubledoubleintint
ObjectObject
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
Constructor Chaining (Cont..)
Public Class A Sub New Console.WriteLine(“A”) End SubEnd Class
Public Class B Inherits A Sub New Console.WriteLine(“B”) End Sub End Class
public class A{ public A() { Console.WriteLine(“A”); }}public class B:A{ public B() { Console.WriteLine(“B”); } }
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
• Set of rules• Can implements multiple interfaces in single class
Interfaces
HumanHuman
ManMan WomanWoman
PlantPlant AnimalAnimal
Living ThingLiving Thing Non Living ThingNon Living Thing
lilylily RoseRose LionLion TigerTiger
InterfacesInterfaces
Abstract Classes
Abstract Classes
SealedClasses
SealedClasses
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
if(x == y){ // X is equal to Y}else{//X is not equal to Y}
switch(x){case 2: //x equals 2 break;default: //x does not equal 2 break;}
Conditional Statements
If x == y Then ‘ X is equal to YElse ‘X is not equal to YEnd If
Select Case x Case 2 ‘x is equal to 2 Case Else ‘x is not equal to 2 End Select
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
x = 0;do{ Console.WriteLine(x); }while(x < 0);
for(x = 0;x<100;x++) Console.Write(x);
Loops
x = 0;while(x != 10){ Console.WriteLine(x); x++;}
x = 0While x >= 10 Console.WriteLine(x) x++;End While
x = 0Do Console.WriteLine(x) Loop While x < 0
For x = 0 To 100 Console.WriteLine(x)Next
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
Loops
int[] x = new int[] { 10, 20, 30, 40 };
foreach (int i in x){ Console.WriteLine(i);}
Dim x() As Integer = {10, 20, 30, 40}
For Each i As Integer In x Console.WriteLine(i)Next
• foreach loop• Iterates over arrays or any class that implements the IEnumerable
interface