Presentation is loading. Please wait.

Presentation is loading. Please wait.

Michael Olivero Microsoft Student Ambassador for FIU Pick up your free drink below to your left. 1 per person please.

Similar presentations


Presentation on theme: "Michael Olivero Microsoft Student Ambassador for FIU Pick up your free drink below to your left. 1 per person please."— Presentation transcript:

1 Michael Olivero Microsoft Student Ambassador for FIU mike@mike95.com Pick up your free drink below to your left. 1 per person please.

2 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

3 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

4 Topics Covered Today .NET Framework & CLR .NET Base Class Library  Using Classes & Structures  Constructors, Methods, In/Out  Scope & Access Levels  Garbage Collection  Give Away

5 .NET Framework & CLR  After this lesson you will be able to 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

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

7 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

8 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

9 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.

10 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.

11 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

12 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.

13 Inspection of Assembly DEMO  IL = Microsoft's Intermediate Language (i.e. generic asm)  ILDasm = IL Disassembler c:\> ildasm hello.exe

14 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.

15 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.

16 Topics Covered Today.NET Framework & CLR.NET Framework & CLR .NET Base Class Library Using Classes & Structures Constructors, Methods, In/Out Scope & Access Levels Garbage Collection Give Away

17 .NET Base Class Library  After this lesson you will be able to 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

18 .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 http://www.mike95.com/Microsoft/S1/Namespaces.html

19 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.

20 Using.NET Framework Types  Value Types  Visual Basic.NET Syntax  Dim myInteger As Integer = 42  Visual C# Syntax  int myInteger = 42;

21 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()

22 Using.NET Framework Types  All variables 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.

23 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() );

24 Using.NET Framework Types  Using namespaces  Imports System.Windows.Forms (VB.NET)  using System.Windows.Forms; (C#)  Creating aliases to namespaces or classes (C# only)  Using myAlias = MyNameSpace.MyClass

25 Referencing External Libraries  Importing external libraries into your projects  Must create a reference

26 Quick Demo  Importing namespaces  Where they are specified  Importing and using external assemblies using references

27 Topics Covered Today.NET Framework & CLR.NET Framework & CLR.NET Base Class Library.NET Base Class Library  Using Classes & Structures Constructors, Methods, In/Out Scope & Access Levels Garbage Collection Give Away – Visual Studio.NET

28 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

29 Creating Classes  Use the class keyword as in Java & C++  class Tree { //class member implementation }

30 Creating Structures  Use the struct keyword as in C++  struct Tree { // Tree implementation goes here }  Structure Tree ' Tree implementation goes here End Structure

31 Adding Members  class Tree { int Age; } class Tree Age as Integer End Class

32 Nested Types  class Tree { // Tree class code goes here class Branch { // Branch class code goes here. } }

33 Instantiating User-defined Types  Must use new keyword with classes  Structure types are allocated on the stack

34 Topics Covered Today.NET Framework & CLR.NET Framework & CLR.NET Base Class Library.NET Base Class Library Using Classes & Structures Using Classes & Structures  Using Methods, In/Out, Constructor Scope & Access Levels Garbage Collection Give Away – Visual Studio.NET

35 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

36 Adding Methods  C# – fuctions Public void NoReturnMethod() { } Public int ADD( int A, int B ) { return A + B; }

37 Calling Methods in VB  VB.NET requires parenthesis on all calls (including subs)  Example: DisplayInfo( “Hello” ) vs. DisplayInfo “Hello”

38 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

39 Parameters  Three options:  pass-by-value (default)  pass-by-reference  pass-by-result ("copy-out")

40 public class App { public static void Main() { 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 1: pass-by-value with a value type  Bits are copied… Stack i99 stack frame for Main stack frame for Foo value100

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

42 Case 3: pass-by-value with a reference type  Reference is copied… public class App { public static void Main() { 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(); } } Stack aTree Tree Data aTree A Tree

43 public class App { public static void Main() { Tree aTree; aTree = new Tree(); aTree.Age = 99; 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(); } } Case 4: pass-by-ref with a reference type  Reference to reference is passed… Stack aTree Tree A

44 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]; }

45  DEMO  Struct vs. Class  OUT param

46 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 (~)

47 Topics Covered Today.NET Framework & CLR.NET Framework & CLR.NET Base Class Library.NET Base Class Library Using Classes & Structures Using Classes & Structures Using Methods, In/Out, Constructor Using Methods, In/Out, Constructor  Scope & Access Levels Garbage Collection Give Away – Visual Studio.NET

48 Scope & Access Levels  After this lesson you will be able to:  Describe meaning of each access level  Explain scope

49 Scope & Access Levels (2)  There are 4 keywords for type access  Public  Private  Protected  Internal (special)  Internal can be used by itself, or in conjunction with Protected.

50 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.

51 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

52 Topics Covered Today.NET Framework & CLR.NET Framework & CLR.NET Base Class Library.NET Base Class Library Using Classes & Structures Using Classes & Structures Using Methods, In/Out, Constructor Using Methods, In/Out, Constructor Scope & Access Levels Scope & Access Levels  Garbage Collection (3) Give Away – Visual Studio.NET

53 Garbage Collection  After this lesson you will be able to:  Describe how garbage collection manages the reclamation of unused memory

54 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.

55 Garbage Collection  How it works

56 Topics Covered Today.NET Framework & CLR.NET Framework & CLR.NET Base Class Library.NET Base Class Library Using Classes & Structures Using Classes & Structures Using Methods, In/Out, Constructor Using Methods, In/Out, Constructor Scope & Access Levels Scope & Access Levels Garbage Collection (3) Garbage Collection (3)  Give Aways  Imagine CUP Programming Competition


Download ppt "Michael Olivero Microsoft Student Ambassador for FIU Pick up your free drink below to your left. 1 per person please."

Similar presentations


Ads by Google