Вы находитесь на странице: 1из 111

Current Popular IT I 2nd Session

Learning Outcomes
Learner can use C# 3 language Learner can use VB 9 Language

Bina Nusantara

Copyright Surya Sujarwo 2008

Material Outline

Bina Nusantara

C#:Pre-processing directives C#:Types C#:Variables C#:Conversions C#:Expressions C#:Statements C#:Namespaces C#:Classes C#:Structs C#:Arrays C#:Interfaces C#:Enums
Copyright Surya Sujarwo 2008

C#:Delegate C#:Exceptions C#:Attributes C#:Unsafe code VB9:Pre-processing directives VB9:General Concepts VB9:Attributes VB9:Source Files and Namespaces VB9:Types VB9:Conversions VB9:Type Members VB9:Statements VB9:Expressions

C#:Pre-processing directives
Conditional Compilation Diagnostic Directive

Region Directive

Bina Nusantara

References: CSharp Language Specification

C#:Types
Category Value types Simple types Description Signed integral: sbyte, short, int, long Unsigned integral: byte, ushort, uint, ulong Unicode characters: char IEEE floating point: float, double High-precision decimal: decimal Boolean: bool User-defined types of the form enum E {...} User-defined types of the form struct S {...} Extensions of all other value types with a null value Ultimate base class of all other types: object Unicode strings: string User-defined types of the form class C {...} User-defined types of the form interface I {...} Single- and multi-dimensional, for example, int[] and int[,] User-defined types of the form e.g. delegate int D(...)

Reference types

Enum types Struct types Nullable types Class types

Interface types Array types Delegate types

Bina Nusantara

References: CSharp Language Specification

C#:Variables
Type of Variable Non-nullable value type Nullable value type object Class type Interface type Possible Contents A value of that exact type A null value or a value of that exact type A null reference, a reference to an object of any reference type, or a reference to a boxed value of any value type A null reference, a reference to an instance of that class type, or a reference to an instance of a class derived from that class type A null reference, a reference to an instance of a class type that implements that interface type, or a reference to a boxed value of a value type that implements that interface type A null reference, a reference to an instance of that array type, or a reference to an instance of a compatible array type A null reference or a reference to an instance of that delegate type

Array type Delegate type


Bina Nusantara

References: CSharp Language Specification

C#:Conversions
Implicit conversions and explicit conversions

Bina Nusantara

References: CSharp Language Specification

C#:Expressions
Expression x.m x(...) x[...] x++ x-new T(...) new T(...){...} new {...} new T[...] typeof(T) checked(x) unchecked(x) default(T) delegate {...} Unary +x -x !x ~x ++x --x (T)x Multiplicative x*y x/y x%y Additive x+y xy References: CSharp Language Specification Bina Nusantara Category Primary Description Member access Method and delegate invocation Array and indexer access Post-increment Post-decrement Object and delegate creation Object creation with initializer Anonymous object initializer Array creation Obtain System.Type object for T Evaluate expression in checked context Evaluate expression in unchecked context Obtain default value of type T Anonymous function (anonymous method) Identity Negation Logical negation Bitwise negation Pre-increment Pre-decrement Explicitly convert x to type T Multiplication Division Remainder Addition, string concatenation, delegate combination Subtraction, delegate removal

C#:Expressions (Continue)
Shift Relational and type testing x << y x >> y x<y x>y x <= y x >= y x is T x as T Equality Logical AND Logical XOR Logical OR Conditional AND Conditional OR Null coalescing Conditional Assignment or anonymous function x == y x != y x&y x^y x|y x && y x || y X ?? y x?y:z x=y x op= y (T x) => y References: CSharp Language Specification Shift left Shift right Less than Greater than Less than or equal Greater than or equal Return true if x is a T, false otherwise Return x typed as T, or null if x is not a T Equal Not equal Integer bitwise AND, boolean logical AND Integer bitwise XOR, boolean logical XOR Integer bitwise OR, boolean logical OR Evaluates y only if x is true Evaluates y only if x is false Evaluates to y if x is null, to x otherwise Evaluates y if x is true, z if x is false Assignment Compound assignment; supported operators are *= /= %= += -= <<= >>= &= ^= |= Anonymous function (lambda expression)

Bina Nusantara

C#:Statements
Local variable declaration Local constant declaration

Expression statement

if statement

Bina Nusantara

References: CSharp Language Specification

C#:Statements (Continue)
switch statement while statement

do statement for statement

Bina Nusantara

References: CSharp Language Specification

C#:Statements (Continue)
foreach statement break statement

continue statement

goto statement

Bina Nusantara

References: CSharp Language Specification

C#:Statements (Continue)
return statement yield statement

throw and try statements

Bina Nusantara

References: CSharp Language Specification

C#:Statements (Continue)
checked and unchecked statements lock statement

using statements

Bina Nusantara

References: CSharp Language Specification

C#:Namespaces
Global Namespace Namespace declaration
Using namespace and alias

Bina Nusantara

References: CSharp Language Specification

C#:Classes
Members
Member Constants Fields Methods Properties Indexers Events Operators Constructors Destructors Types Description Constant values associated with the class Variables of the class Computations and actions that can be performed by the class Actions associated with reading and writing named properties of the class Actions associated with indexing instances of the class like an array Notifications that can be generated by the class Conversions and expression operators supported by the class Actions required to initialize instances of the class or the class itself Actions to perform before instances of the class are permanently discarded Nested types declared by the class

Bina Nusantara

References: CSharp Language Specification

C#:Classes (Continue)
Accessibility
Accessibility public protected Access not limited Access limited to this class or classes derived from this class Meaning

internal protected internal


private

Access limited to this program Access limited to this program or classes derived from this class
Access limited to this class

Bina Nusantara

References: CSharp Language Specification

C#:Classes (Continue)
function members

Bina Nusantara

References: CSharp Language Specification

C#:Classes (Continue)
function members (continue)

Bina Nusantara

References: CSharp Language Specification

C#:Classes (Continue)
Methods Parameters:
A value parameter A reference parameter An output parameter A parameter array

Bina Nusantara

References: CSharp Language Specification

C#:Structs


Bina Nusantara

Value types Inherit System.ValueType Assignment to a variable create a copy of the value. The default value of value type fields is their default values and reference type fields is null. Boxing and unboxing operation are used to convert between a struct type and object. The meaning of this is different for structs Instance field declarations not permitted to use variable initializers not permitted to declare a parameterless instance constructor not permitted to declare a destructor
References: CSharp Language Specification

C#:Arrays

Bina Nusantara

References: CSharp Language Specification

C#:Interfaces

Bina Nusantara

References: CSharp Language Specification

C#:Enums

Bina Nusantara

References: CSharp Language Specification

C#:Delegate

Bina Nusantara

References: CSharp Language Specification

C#:Exceptions
Exceptions System.ArithmeticException

System.ArrayTypeMismatchException
System.DivideByZeroException System.IndexOutOfRangeException System.InvalidCastException System.NullReferenceException System.OutOfMemoryException System.OverflowException

Reasons A base class for exceptions that occur during arithmetic operations, such as System.DivideByZeroException and System.OverflowException. Thrown when a store into an array fails because the actual type of the stored element is incompatible with the actual type of the array. Thrown when an attempt to divide an integral value by zero occurs. Thrown when an attempt to index an array via an index that is less than zero or outside the bounds of the array. Thrown when an explicit conversion from a base type or interface to a derived type fails at run time. Thrown when a null reference is used in a way that causes the referenced object to be required. Thrown when an attempt to allocate memory (via new) fails. Thrown when an arithmetic operation in a checked context overflows.

System.StackOverflowException
System.TypeInitializationException
References: CSharp Language Specification

Thrown when the execution stack is exhausted by having too many pending method calls; typically indicative of very deep or unbounded recursion. Thrown when a static constructor throws an exception, and no catch clauses exists to catch it.

Bina Nusantara

C#:Attributes

Bina Nusantara

References: CSharp Language Specification

C#:Unsafe code

Bina Nusantara

References: CSharp Language Specification

VB9:Pre-processing directives
Conditional Compilation Region Directives

External Source Directives

External Checksum Directives

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts
Declarations (named entities)
Overloading using signatures (name of type member, number of type parameters, the numbers and types of the members parameters)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Scope

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Inheritance
Inheritance is transitive.(A->B, B->C, then C{A,B,C}) A derived type extends, but cannot narrow. (A->B, B{A,B}, X B{B}) Conversion always exists from a derived type to its base type. All types must have a base type, except for the type Object. Thus, Object is the ultimate base type of all types, and all types can be converted to it. Circularity in derivation is not permitted. A type may not directly or indirectly derive from a type nested within it.

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


MustInherit and NotInheritable Classes

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Interfaces and Multiple Inheritance

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Interfaces and Multiple Inheritance (Continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Shadowing

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Shadowing (Continue) Hides only the individual signature Print Base

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Shadowing (Continue) Only shadows methods with same signature Print Base

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementation

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementation (Continue)
All members of interfaces must be implemented even though they cant be accessed directly

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementation (Continue)
Even MustInherit must provide implementation of all implemented interface, however can be defer by MustOverride.

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementation (Continue)
Re-Implement an interface that its base type implement

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementation (Continue)
Re-Implement an interface that its base type implement by override

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementing Methods
Must have same parameters

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementing Methods (continue)
Can implement any number of interface type members

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementing Methods (continue)
Implement Generic Interface must supply the type

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Implementing Methods (continue)
Theres a possibility that Generic Interface may not be implementable

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Polymorphism

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Overriding Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Overriding Methods (continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Accessibility
Accessibility domain of A and A.X is unlimited. Accessibility domain of A.Y, B, B.X, B.Y, B.C, B.C.X, and B.C.Y is the containing program.

Accessibility domain of A.Z is A.


Accessibility domain of B.Z, B.D, B.D.X, and B.D.Y is B, including B.C and B.D.

Accessibility domain of B.C.Z is B.C.


Accessibility domain of B.D.Z is B.D.

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Type and Namespace Names

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:General Concepts (Continue)


Variables
Represent a storage location. Has a type and always initialized to the default value. It is not possible to access uninitialized memory.

Generic Types and Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Attributes
Can be retrieved at run time through .NET Frameworks reflection APIs.

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Attributes (Continue)
Attribute usage

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Attributes (Continue)
Multiple Attribute usage

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Attributes (Continue)
Attribute inheritance

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Source Files and Namespaces


Global Namespace

Compilation Options
Option Explicit [On|Off] Option Strict [On|Off] Option Compare [Binary|Text] Option Infer [On|Off]

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Source Files and Namespaces


Imports Statement

Imports Aliases

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Source Files and Namespaces


Namespace | Types Imports

XML Namespace Imports

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Value Types and Reference Types

Nullable Value Types

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Primitive Types:

Bina Nusantara

Boolean Date Char String Decimal Byte SByte UShort Short UInteger Integer

ULong Long Single Double

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Enumerations

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Classes

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Classes (continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Structures

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Modules

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Interfaces
Interfaces Inheritance

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Arrays

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Delegates

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Partial types

Constructed types

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Types
Open Types and Close Types

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Conversions
Implicit and Explicit Conversions

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Conversions
Boolean Conversions
True value convert to:

Byte : 255 UShort: 65535 UInteger: 4294967295 ULong: 18446744073709551615 SByte, Short, Integer, Long, Decimal, Single, Double : -1

False value convert to 0. 0 convert to false. Others value convert to true.

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Conversions
User-Defined Conversions

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Interface Method Implementation

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Interface Method Implementation (continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
External Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Shared Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Parameters

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Parameters (Continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Event Handling

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Extension Methods

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Constructors

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Events

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Constants

Read-Only Variables

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
WithEvents Variables

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Variable Initializers

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Variable Initializers (continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Array-Size Initializers
Array-Element Initializers

Properties

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Type Members
Operators

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Blocks and Label

Local Declaration Statements


Implicit Local Declaration

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
With Statementss

SyncLock Statements

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Events Statements

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Assignment Statements
Regular Assignment Compound Assignment Mid Assignment Select Case

Conditional Statements
If Then Else

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Loop Statements
WhileEnd While, DoLoop For EachNext

ForNext

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Exception-Handling Statements
Structured Unstructured

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Array-Handling Statements

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Statements
Using Statements

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions

Bina Nusantara

Constant Expressions Late-Bound Expressions Simple Expressions Type Expressions Member Access Expressions Dictionary Member Access Invocation Expressions Index Expressions New Expressions Cast Expressions Operator Expressions
References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

Arithmetic Expressions Relational Expressions Like Operator Concatenation Operator Logical Operators Shift Operators Boolean Expressions Lambda Expressions Query Expressions Conditional Expressions XML Literal Expressions XML Member Access Expressions

VB9:Expressions
Dictionary Member Access

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
Type Arguments Inference

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
New Expressions
Object-Creation

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
New Expressions (continue)
Array-Creation

Anonymous Object-Creation

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
New Expressions (continue)
Anonymous Object-Creation (continue)

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
Cast Expressions

Like Expressions
? ->single character * ->zero or more characters # -> single digit (0-9) [ab] -> any single character in the list [!ab] -> any single character not in the list

Short-circuiting Logical Operators (AndAlso, OrElse)


Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
Lambda Expressions

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
Query Expressions

Conditional Expressions

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

VB9:Expressions
XML Literal Expression and Member Access Expressions

Bina Nusantara

References: Visual Basic Language Specification 9.0 (Paul Vick,2007)

Thats All Thank You for the Attention

Bina Nusantara

Вам также может понравиться