AUC Technologies AUC Technologies Projects Consulting, Development, Mentoring, and Training Company .NET Basic Fundamentals Presented By : Muhammad Atif Hussain Deputy Manager IT (Takaful Pakistan Limited) Technologies Consultant (AUC Technologies) MCS(KU) MSCS(SZABIST) MCP MCAD MCSD MCTS (Windows, Web, Distributed Applications) MCPD (Enterprise Applications) MCT(Microsoft Certified Trainer)
37
Embed
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company.NET Basic Fundamentals Presented By : Muhammad Atif Hussain Deputy Manager.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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)
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
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
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company
AUC TechnologiesAUC Technologies
Projects Consulting, Development, Mentoring, and Training Company