Docstoc

Power Point - PowerPoint Present

Document Sample
Power Point - PowerPoint Present Powered By Docstoc
					Pick up your free drink below to your left. 1 per person
please.




               Michael Olivero
               Microsoft Student Ambassador for FIU
               mike@mike95.com
Knowledge Prerequisites

 Attendees should meet the following
 prerequisites:
   Be familiar with the Microsoft Visual Studio
    Environment
   Have some experience in an Object oriented
    language such as Java or C++
   Have a moderate understanding of SQL syntax
   Have some experience building HTML pages
Over view of Semester

 How  many are new?
 Introduction to .NET Framework
 Setting up IIS on Windows XP
 ASP.NET
 Setting up SQL Server
 Advanced ASP.NET
 Other topics
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
   Constructors, Methods, In/Out
   Scope & Access Levels
   Garbage Collection
   Give Away
.NET Framework & CLR

      this lesson you will be able to
 After
 describe:
   The elements of the .NET framework
   Parts of an assembly & identify what is
    contained in each part
   How a .NET application is compiled &
    executed
Overview of .NET Framework

 Itis a managed type-safe
  environment
 Consists of two main components
    Common   Language Runtime
    .NET Framework class library
Overview of .NET Framework

 Common   Language Runtime
  An environment that manages code
    Machine Code compilation, memory
     allocation, thread management, and
     Garbage collection
  Common type system (CTS)
    Enforces strict type-safety
    Ensures code is executed in safe
     environment by enforcing code
     access security
Overview of .NET Framework

 .NET   Framework class library
   Collection  of useful and reusable types
   Types are objected-oriented and fully
    extensible
   Permits you to add rich functionality to
    your application
   We will discuss this in more detail on
    later slides
Languages and the .NET
Framework
   .NET Framework is cross-language compatible
      Components can interact no matter what
       language they were originally built with.
      Language interoperability is OOP compatible
      .NET Languages (VB, C#) are compiled into
       Intermediate Language (IL) or (MSIL)
      Common Language Specification (CLS)
       defines standard for IL where all compilers
       should adhere to.
Easier reuse & integration

 CLS   ensures type compatibility
  Because   all compiled code is in IL, all
   primitive types are represented as .NET
   types.
  An int in C# and an int in VB are both
   represented by an Int32 in IL
  This allows easy communication
   between components without costly
   conversion / check code.
Structure of .NET Application

 Assembly       – primary unit of .NET app
  A self describing collection of code,
   resources, and metadata.
 Parts   of Assembly
   Assembly  manifest
    Contains information about what is
     within the assembly. It provides:
           Identity information (Name & version)
           List of types exposed by assembly
           List of dependent assemblies
           List of code access security instructions,
            including permissions required by assembly
Structure of .NET Application

   One manifest per assembly
   Assembly contains 1 or more modules
   Each Module contains 1 or more types composed
    of
      Reference types (classes)
      Value types (structures)
      More of this on a later slide.
Inspection of Assembly
  DEMO
   IL = Microsoft's Intermediate Language (i.e. generic asm)
   ILDasm = IL Disassembler
c:\> ildasm hello.exe
Compilation & Execution

 !NOT!   compiled to binary machine
  code
 IL compiled to binary machine code
  with JIT (Just In Time) compilation.
 As IL code is encountered, JIT
  compiles to machine code.
 Each portion compiled only once.
Summary
   .NET Framework
       Two Core parts
          Common Language Runtime
                 Provides core services
            Base Class Library
                 Exposes rich set of pre-developed classes
       CLS
          defines minimum standard for IL
          Type compatibility
       Assembly
          Primary unit of .NET application
          Consists of
                 Assembly Manifest, one or more modules, and code for
                  application.
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
    Using Classes & Structures
    Constructors, Methods, In/Out
    Scope & Access Levels
    Garbage Collection
    Give Away
.NET Base Class Library
      this lesson you will be able to
 After
 describe:
   The  .NET base class library
   Difference between value & reference
    types
   Create a reference to a namespace
   Create an instance of .NET framework
    class & value type
.NET Base Class Library
   Provides much of the services you will need when writing
    your application
   Organized using Namespaces
       Logical groupings of related classes
       Namespaces organized hierarchically, the root namespace is
        System
   Examples:
       System;
       System.Data;
       System.Data.SQLClient;
       http://www.mike95.com/Microsoft/S1/Namespaces.html
Reference & Value Types
 Memory    is of two forms: stack & heap
  Stack   is local memory – used for value
   types.
  Heap is general memory – used for
   reference types.
  A reference type is allocated in the heap,
   but it’s reference variable is allocated on
   the stack.
Using .NET Framework Types
 Value   Types
   Visual Basic .NET Syntax
     Dim myInteger As Integer = 42
   Visual C# Syntax
     int myInteger = 42;
Using .NET Framework Types
 Declaration for Reference Types
    Visual Basic .NET
         Dim myForm As System.Windows.Forms.Form
    Visual C#
       System.Windows.Forms.Form myForm;




 Initialization
    myForm = new System.Windows.Form.Form()
Using .NET Framework Types
 Allvariables are assigned default values
   Numeric are assigned zero
   Boolean are assigned False
   Reference are assigned null
   However, you should not rely on these
    initial values.
Automatic Boxing / UnBoxing

   Values types can be used
    interchangeably with related
    reference types.
   Ex: A value type can be treated as a
    reference and vice versa.
      int age = 5;
      System.Console.WriteLine( age.ToString() );
Using .NET Framework Types
 Using   namespaces
   Imports System.Windows.Forms (VB.NET)
   using System.Windows.Forms; (C#)

 Creatingaliases to namespaces or
 classes (C# only)
   Using   myAlias = MyNameSpace.MyClass
Referencing External Libraries
 Importing   external libraries into your
 projects
   Must   create a reference
Quick Demo
   Importing namespaces
       Where they are specified
   Importing and using external
    assemblies using references
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
    Constructors, Methods, In/Out
    Scope & Access Levels
    Garbage Collection
    Give Away – Visual Studio .NET
Using Classes and Structures

 After   this lesson you will be able to:
   Create a new class or structure
   Create an instance of a class or structure
   Explain difference between a class /
    structure
   Create a nested type
Creating Classes
 Use   the class keyword as in Java & C++
   class   Tree
   {
       //class member implementation
   }
Creating Structures
 Use   the struct keyword as in C++
   struct   Tree
   {
        // Tree implementation goes here
   }

   StructureTree
    ' Tree implementation goes here
   End Structure
Adding Members
 class   Tree
 {
     int Age;
 }

 class Tree
   Age as Integer
 End Class
Nested Types
 class   Tree
 {
     // Tree class code goes here
     class Branch
     {
        // Branch class code goes here.
     }
 }
Instantiating User-defined Types
 Must  use new keyword with classes
 Structure types are allocated on the
  stack
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
   Using Methods, In/Out, Constructor
    Scope & Access Levels
    Garbage Collection
    Give Away – Visual Studio .NET
Using Methods
 After   this lesson you will be able to:
   Create a new method
   Specify return types for your method
   Specify input & output parameters
   Create a constructor & destructor
Adding Methods
 C#   – fuctions
   Public void NoReturnMethod()
   {

   }

   Public int ADD( int A, int B )
   {
     return A + B;
   }
Calling Methods in VB
 VB.NET   requires parenthesis on all
  calls (including subs)
 Example:
   DisplayInfo( “Hello” )
   vs.
   DisplayInfo “Hello”
Method Variables
   Variables declared within methods have method
    scope
   Variables within for or while loop have scope only
    within loop
      In general, variable scope is determined by It’s
       nearest set of braces for C#
   VB has “static” declaration
      Persists in memory for multiple function calls
         Sample use: You would use a Static variable
          for a method that needed to keep track of how
          many times it had been called.
      C# has different meaning for static
Parameters
 Three   options:
   pass-by-value (default)
   pass-by-reference
   pass-by-result ("copy-out")
Case 1: pass-by-value
with a value type
 Bits      are copied…
                                      value   100   stack frame for Foo


public class App                                    stack frame for Main
                                       i       99
{
    public static void Main()              Stack
    {
      int i = 99;
      Foo(i);
      System.Console.WriteLine(i);     // i = 99
    }

    private static void Foo(int value)
    {
      value = value + 1;
      System.Console.WriteLine(i); //value = 100
    }
}
Case 2: pass-by-ref with a
value type
 Reference         is passed…
                                     value         stack frame for Foo


public class App
                                                   stack frame for Main
{                                     i       99
    public static void Main()             Stack
    {
      int i = 99;
      Foo(ref i);
      System.Console.WriteLine(i);   // i = 100
    }

    private static void Foo(ref int value)
    {
      value = value + 1;
    }
}
Case 3: pass-by-value
with a reference type                              Tree
 Reference          is copied…
                                       A           aTree
public class App
{
    public static void Main()      aTree
                                                    Tree
    {                                               Data
                                       Stack
      Tree aTree;
      aTree = new Tree();
      aTree.Age = 99;
      Foo2(aTree);
      System.Console.WriteLine(aTree.Age);// 100
    }

    private static void Foo2(Tree A)
    {
      A.Age = A.Age + 1; // 100
      A = new Tree();
    }
}
Case 4: pass-by-ref with a
reference type
 Reference    to reference
     is passed…                     A
public class App
{
    public static void Main()      aTree
    {                                              Tree
                                       Stack
      Tree aTree;
      aTree = new Tree();
      aTree.Age = 99;                              Tree
      Foo2(ref aTree);
      System.Console.WriteLine(aTree.Age);// 100
    }

    private static void Foo2(ref Tree A)
    {
      A.Age = A.Age + 1; // 100
      A = new Tree();
    }
}
Out Parameters
   C# Only
   Useful if you want method to return more than one value
   Example:
       char FirstChar;
       char SecondChar;
       SplitString( “AB”, out FirstChar, out SecondChar );

       Void SplitString( string input, char out FC, char out SC )
       {
         FC = input[0];
         SC = input[1];
       }
   DEMO
       Struct vs. Class
       OUT param
Constructors / Destructors
   Constructors
       First method called when type is created
          VB is always “Sub New()”
          C# is a method with same name as class
       Used to initialize values in class
       Never returns a value
       Can call other methods
   Destructors
       Last method run by a class
          VB is Sub Finalize()
          C# is method with same name as class prefixed by (~)
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
   Using Methods, In/Out, Constructor
   Scope & Access Levels
    Garbage Collection
    Give Away – Visual Studio .NET
Scope & Access Levels
 After   this lesson you will be able to:
   Describe meaning of each access level
   Explain scope
Scope & Access Levels (2)
 There   are 4 keywords for type access
   Public
   Private
   Protected
   Internal   (special)

        can be used by itself, or in
 Internal
 conjunction with Protected.
Member Access Modifiers
   Public
      Allows access from anywhere
   Private
      Allows access only from members within the type that
        defines it
   Protected
      Equivalent to Private with the addition of access through
        inherited objects
   Internal (Friend in VB)
      Access from within all objects in Assembly
   Protected Internal
      Union of Protected & Internal: all objects from assembly +
        members within the type that defines class + inherited class
        members.
Access Modifiers for
Nested Types
 protected   class Tree
  {
      private class Branch
      {
      }
  }
 Usually nested type is used by class that
  contains it; thus typically private.
 Rarely would the type be made public
 Will always be bounded by the access
  qualifier of surrounding type
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
   Using Methods, In/Out, Constructor
   Scope & Access Levels
   Garbage Collection (3)
    Give Away – Visual Studio .NET
Garbage Collection
 After   this lesson you will be able to:
   Describe how garbage collection manages
    the reclamation of unused memory
Garbage Collection
   Automatic memory management
   When object is no longer reference, it is marked for
    garbage collection
   Always running
   Low priority thread under normal circumstances
      Moves up in priority temporarily if memory
       becomes limited
   The garbage collector continuously traces reference
    tree and disposes of objects containing circular
    references in addition to disposing of unreferenced
    objects.
Garbage Collection
 How   it works
Topics Covered Today
   .NET Framework & CLR
   .NET Base Class Library
   Using Classes & Structures
   Using Methods, In/Out, Constructor
   Scope & Access Levels
   Garbage Collection (3)
   Give Aways
   Imagine CUP Programming Competition

				
DOCUMENT INFO