Академический Документы
Профессиональный Документы
Культура Документы
Learning Outcomes
Learner can use C# 3 language Learner can use VB 9 Language
Bina Nusantara
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
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
Bina Nusantara
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
C#:Conversions
Implicit conversions and explicit conversions
Bina Nusantara
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
C#:Statements (Continue)
switch statement while statement
Bina Nusantara
C#:Statements (Continue)
foreach statement break statement
continue statement
goto statement
Bina Nusantara
C#:Statements (Continue)
return statement yield statement
Bina Nusantara
C#:Statements (Continue)
checked and unchecked statements lock statement
using statements
Bina Nusantara
C#:Namespaces
Global Namespace Namespace declaration
Using namespace and alias
Bina Nusantara
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
C#:Classes (Continue)
Accessibility
Accessibility public protected Access not limited Access limited to this class or classes derived from this class Meaning
Access limited to this program Access limited to this program or classes derived from this class
Access limited to this class
Bina Nusantara
C#:Classes (Continue)
function members
Bina Nusantara
C#:Classes (Continue)
function members (continue)
Bina Nusantara
C#:Classes (Continue)
Methods Parameters:
A value parameter A reference parameter An output parameter A parameter array
Bina Nusantara
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
C#:Interfaces
Bina Nusantara
C#:Enums
Bina Nusantara
C#:Delegate
Bina Nusantara
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
C#:Unsafe code
Bina Nusantara
VB9:Pre-processing directives
Conditional Compilation Region Directives
Bina Nusantara
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
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
Bina Nusantara
VB9:Attributes
Can be retrieved at run time through .NET Frameworks reflection APIs.
Bina Nusantara
VB9:Attributes (Continue)
Attribute usage
Bina Nusantara
VB9:Attributes (Continue)
Multiple Attribute usage
Bina Nusantara
VB9:Attributes (Continue)
Attribute inheritance
Bina Nusantara
Compilation Options
Option Explicit [On|Off] Option Strict [On|Off] Option Compare [Binary|Text] Option Infer [On|Off]
Bina Nusantara
Imports Aliases
Bina Nusantara
Bina Nusantara
VB9:Types
Value Types and Reference Types
Bina Nusantara
VB9:Types
Primitive Types:
Bina Nusantara
Boolean Date Char String Decimal Byte SByte UShort Short UInteger Integer
VB9:Types
Enumerations
Bina Nusantara
VB9:Types
Classes
Bina Nusantara
VB9:Types
Classes (continue)
Bina Nusantara
VB9:Types
Structures
Bina Nusantara
VB9:Types
Modules
Bina Nusantara
VB9:Types
Interfaces
Interfaces Inheritance
Bina Nusantara
VB9:Types
Arrays
Bina Nusantara
VB9:Types
Delegates
Bina Nusantara
VB9:Types
Partial types
Constructed types
Bina Nusantara
VB9:Types
Open Types and Close Types
Bina Nusantara
VB9:Conversions
Implicit and Explicit Conversions
Bina Nusantara
VB9:Conversions
Boolean Conversions
True value convert to:
Byte : 255 UShort: 65535 UInteger: 4294967295 ULong: 18446744073709551615 SByte, Short, Integer, Long, Decimal, Single, Double : -1
Bina Nusantara
VB9:Conversions
User-Defined Conversions
Bina Nusantara
VB9:Type Members
Interface Method Implementation
Bina Nusantara
VB9:Type Members
Interface Method Implementation (continue)
Bina Nusantara
VB9:Type Members
Methods
Bina Nusantara
VB9:Type Members
External Methods
Bina Nusantara
VB9:Type Members
Shared Methods
Bina Nusantara
VB9:Type Members
Parameters
Bina Nusantara
VB9:Type Members
Parameters (Continue)
Bina Nusantara
VB9:Type Members
Event Handling
Bina Nusantara
VB9:Type Members
Extension Methods
Bina Nusantara
VB9:Type Members
Constructors
Bina Nusantara
VB9:Type Members
Events
Bina Nusantara
VB9:Type Members
Constants
Read-Only Variables
Bina Nusantara
VB9:Type Members
WithEvents Variables
Bina Nusantara
VB9:Type Members
Variable Initializers
Bina Nusantara
VB9:Type Members
Variable Initializers (continue)
Bina Nusantara
VB9:Type Members
Array-Size Initializers
Array-Element Initializers
Properties
Bina Nusantara
VB9:Type Members
Operators
Bina Nusantara
VB9:Statements
Blocks and Label
Bina Nusantara
VB9:Statements
With Statementss
SyncLock Statements
Bina Nusantara
VB9:Statements
Events Statements
Bina Nusantara
VB9:Statements
Assignment Statements
Regular Assignment Compound Assignment Mid Assignment Select Case
Conditional Statements
If Then Else
Bina Nusantara
VB9:Statements
Loop Statements
WhileEnd While, DoLoop For EachNext
ForNext
Bina Nusantara
VB9:Statements
Exception-Handling Statements
Structured Unstructured
Bina Nusantara
VB9:Statements
Array-Handling Statements
Bina Nusantara
VB9:Statements
Using Statements
Bina Nusantara
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
VB9:Expressions
Type Arguments Inference
Bina Nusantara
VB9:Expressions
New Expressions
Object-Creation
Bina Nusantara
VB9:Expressions
New Expressions (continue)
Array-Creation
Anonymous Object-Creation
Bina Nusantara
VB9:Expressions
New Expressions (continue)
Anonymous Object-Creation (continue)
Bina Nusantara
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
VB9:Expressions
Lambda Expressions
Bina Nusantara
VB9:Expressions
Query Expressions
Conditional Expressions
Bina Nusantara
VB9:Expressions
XML Literal Expression and Member Access Expressions
Bina Nusantara
Bina Nusantara