|
|
Namesapce
|
Description
|
|
System
|
Root.
Contains low-level and primitive types
|
|
System.Collections
|
Types for
arrays, lists, queues and stacks. Abstract classes to implement own
collections
|
|
System.ComponentModel
|
Component
creation and containment – attributes, type converters, license
providers
|
|
System.Data
|
Database
access and manipulations
|
|
System.Data.Common
|
Classes
shared by .NET managed data providers
|
|
System.Data.OleDb
|
Managed
provider for OLE DB
|
|
System.Data.SqlClient
|
Managed
provider for SQL server
|
|
System.Drawing
|
GDI+
functionality
|
|
System.IO
|
File
system IO
|
|
System.Math
|
Roots,
trig, etc.
|
|
System.Reflection
|
Obtain
info on and dynamically create types at
run-time
|
|
System.Security
|
Permissions, cryptography and code
access
|
|
System.Threading
|
Supports
multi-threaded apps
|
|
System.Windows.Forms
|
Supports
standard windows apps (forms and
consoles)
|
Table 1
Representative .NET
Namespaces
int
myInteger;
myInteger =
42;
System.Windows.Forms.Form
myForm;
myForm = new
System.Windows.Forms.Form
Widget
mywidget;
myWidget =
new Widget(“doodah”);
i.
fully
qualified name must be used to avoid conflict
ii.
use alias to
choose one name to refer to another class
using myAlias
= MyNamespace.Widget
myNamespace.Widget
widget = new myNamespace.Widget
myAlias
anotherWidget = new myAlias
·
Access
3rd party libraries:
1.
From Solution
Explorer right click projects References node
2.
Choose Add
Reference. Add Reference dialog box appears
3.
Choose tab for
library to reference. .NET libraries are on .NET tab. COM libraries on COM
tab. Local Visual Studio projects on Projects tab
4.
Load library
and double click to add to Selected components box. Click OK to confirm
reference
public class
Widget
{
// Class
implementation goes here
public int
Spin; // Member field
private class
Thing
{
// Nested class
code
}
}
public struct
Vector
{
// Structure
implementation goes here
public int
Add( int first, int second)
{
// Method
implementation
return first +
second;
}
}
public int
Demo2( int p1, ref int p2)
{
}
public void
aWord( out sring Word )
{
Word =
“Mambo”;
}
|
Access
Modifier
|
Affect
|
|
public
|
Accessed
from anywhere
|
|
private
|
Accessed
from members within type defining it
|
|
internal
|
Accessed
from within assembly
|
|
protected
|
Accessed
from members within type or types inheriting from the owning
type
|
|
protected
internal
|
Accessed
from within assembly or from types inheriting from the owning
type
|
Table 2
Access Modifiers
·
Good practice
to assign nested types private access modifier. Can assign other modifiers
but behaviour will never be greater than access modifier of containing
type
·
Can have class
members common to all instances of class via static
keyword
public class
Demo
{
public static
int MyField;
}
·
Methods can
also be shared. Shared methods belong to the type itself, not its
instance. Can not access instance data from objects – only static
variables, variables declared within method or
parameters
·
Access static
members via class name, not instance name.
Demo Object1
= new Demo();
Object1.MyField
= 15; // Incorrect
Demo.MyField
= 15; // Correct
·
Do not need to
instantiate type before accessing static members
·
.NET memory
management scheme called garbage collection (GC)
·
Memory from
object no longer required reclaimed without application
action
·
When variable
goes out of scope object it refers to is no longer referenced. GC
continuously traces the reference tree in background to identify objects
no longer referenced. When found, object deleted and memory
reclaimed
·
GC = low
priority thread. When memory limited GC thread priority
boosted
·
Aims to
maximise app performance and provide less error prone
environment.
·
Nondeterministic
o
no control
over when destructor called
o
do not place
time dependent code in destructor
o
implement
Dispose() to free expensive resources when no longer
needed
·
GC manages
circular references (two object each referring to
one-another)
·
If two objects
only refer to one-another and have no other referees they will be marked
for GC
home |
index |