SlideShare a Scribd company logo
Chapter 1:   Framework Fundamentals   produced by BichTran
Objectives Manage data by using the .NET Framework 2.0 system types. Implement .NET Framework interfaces Control interactions between components by using events and delegates
Agenda Lesson 1: Using Value Types Lesson 2: Using Common Reference Types Lesson 3: Constructing Classes Lesson 4: Converting Between Types  Question and answer Practice test
Using Value Types   Built-in types : sbyte – byte – short – int – uint – float   long –double – decimal   char – bool – date – none  (Pointer to a memory address)   Enumerations : - enum User-defined types: - struct ( Operators  is new in .NET 2.0) struct Cycle {  int _val, _min, _max; public Cycle (int min, int max) { _val = min; _min = min; _max = max;} public static Cycle operator +(Cycle arg1, int arg2) {  arg1.Value += arg2; return arg1; }    public static Cycle operator -(Cycle arg1, int arg2) { arg1.Value -= arg2; return arg1;} }
Using Value Types  (cont.) Use with new feature of Struct (operators) in .NET 2.0 Cycle degrees = new Cycle(0, 359); Cycle quarters = new Cycle(1, 4); for (int i = 0; i <= 8; i++) { degrees += 90; quarters += 1; Console.WriteLine(&quot;degrees = {0}, quarters = {1}&quot;,  degrees, quarters);  } In short, structure types is suitable for simple data, size less than 16 bytes, not be changed after creation, not be cast to a reference type  Summary:   Assigning value-type variables, the data is copied and stored on the stack. Value-types represent simple values, they have methods (as objects) The  Nullable  type is new in .NET 2.0.  Case: use a variable as  nullable  when its value has not been assigned.  Ex: a bool variable has not been assigned
Using Common Reference Types   There are about 2500 built-in reference types in the .NET Framework (not derived from System. ValueType ): Object:  the most general type, any type can be converted to Object. String and StringBuilder:  StringBuilder is more flexible than String   Exception :  unexpected events that interrupt normal execution of an assembly. Use following blocks in case catching exceptions: try {}  catch (Exception ex) {} finally {} Tips:  -  Your own exceptions will be derived from System.ApplicationException -  The runtime will execute only the first Catch block matching exception type. So order of Catch blocks should be from the  most-specific to the least-specific . ,etc.
Constructing Classes   Inheritance:  use inheritance to create new types based on existing ones. Interface:  use interfaces to define a common set of members that must be implemented by related types. For example, the  IComparable , IDisposable, IConvertible  .etc. Partial class:  use partial classes to split a class definition across multiple source files. Use: “ partial ”is preceded keyword “ class ”  Generics (new in .NET 2.0)  NET 1.0 and 1.1 did not support generics. With Generics Without Generics public class Gen<T, U>   { public T t; public U u; public Gen(T _t, U _u)   { t = _t;   u = _u;} } public class Obj  {  public Object t; public Object u; public Obj(Object _t, Object _u)   { t = _t;   u = _u;   } }
Constructing Classes (cont.) With Generics Without Generics Gen<string, string> ga =  new Gen<string, string>(&quot;Hello, &quot;, &quot;World!&quot;); string s = ga.t + ga.u; Gen<double, int> gb =  new Gen<double, int>(10.125, 2005); double db =  gb.t + gb.u; Obj oa = new Obj(&quot;Hello, &quot;, &quot;World!&quot;); string s =  (string)oa.t + (string)oa.u); Obj ob = new Obj(10.125, 2005); double db = (double)ob.t + (int)ob.u); double db = (int)ob.t + (int)ob.u); //  runtime exception
Constructing Classes (cont.) Event:  An event is a message sent by an object to signal the occurrence of an action. Delegate :  A delegate is a class that can hold references to a methods which matches its signature.  ( like method-pointer) public event MyEventHandler MyEvent; public delegate void MyEventHandler(object sender, EventArgs e); Raise event :    MyEventHandler handler = MyEvent; EventArgs e = new EventArgs(); if (handler != null) { // Invokes the delegates. handler(this, e); }  //C# checks to determine whether handler is null. Respond to the event:    private void button1_Click(object sender, EventArgs   e) {} button1.Click += new System.EventHandler(this.button1_Click);
Constructing Classes (cont.) Attributes:  Use attributes to describe assemblies, types, and members. For example :  [Serializable] class ShoppingCartItem {….} Type Forwarding (thinking) Using attribute “TypeForwardedTo” to move a type from one class library to another using System.Runtime.CompilerServices; [assembly:TypeForwardedTo(typeof(DestLib.TypeA))]
Converting Between Types   Conversion:  2 kinds Widening  Conversion  :   the range of the destination type is wider than that of the source type.(implicit conversion) Narrowing conversion:  the range or precision of the source type exceeds that of the destination type, which usually requires explicit conversion.  NOTE :  Use TryParse, TryParseExact, and TryCast are new in .NET 2.0.  Instead of attempting a parsing/conversion and catch the exception if it failed.   Boxing and Unboxing   Boxing  converts a value type to a reference type. Unboxing  converts a reference type to a value type. Unboxing Boxing object o = 123; int i = (int) o; int i = 123; object o = (object) i;
Q&A - Practice test
Thanks for your attention

More Related Content

PPT
Iterator Design Pattern
PPT
Classes & objects new
PPTX
Iterator - a powerful but underappreciated design pattern
PPTX
What is String in Java?
PPTX
Constructor in java
PPTX
Lecture 4.2 c++(comlete reference book)
PPTX
Vectors in Java
PPT
JAVA CONCEPTS
Iterator Design Pattern
Classes & objects new
Iterator - a powerful but underappreciated design pattern
What is String in Java?
Constructor in java
Lecture 4.2 c++(comlete reference book)
Vectors in Java
JAVA CONCEPTS

What's hot (20)

PPTX
PATTERNS09 - Generics in .NET and Java
PPTX
constructor and destructor
PPTX
Class object method constructors in java
PDF
Built in classes in java
PPTX
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
PDF
Lecture20 vector
PPTX
Presentation 4th
PPTX
Unit ii
DOCX
What Do You Mean By NUnit
PPTX
constructors in java ppt
PPTX
Week9 Intro to classes and objects in Java
PPTX
Function Java Vector class
PPTX
Constructor and destructor
PPT
how to create object
PDF
Dagger1
PPTX
Java constructors
PPTX
Dynamic databinding
PPT
PDF
Csharp_Chap03
PPT
Actionscript
PATTERNS09 - Generics in .NET and Java
constructor and destructor
Class object method constructors in java
Built in classes in java
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture20 vector
Presentation 4th
Unit ii
What Do You Mean By NUnit
constructors in java ppt
Week9 Intro to classes and objects in Java
Function Java Vector class
Constructor and destructor
how to create object
Dagger1
Java constructors
Dynamic databinding
Csharp_Chap03
Actionscript
Ad

Viewers also liked (6)

PPT
Developing Collective Leadership
DOC
Ensayo final solucionde problemas
DOC
Lista de citejo para el trabajo de excel
PPTX
Glc istanbul – forum
PDF
Studyshare
KEY
00 IntroduccióN Al Curso
Developing Collective Leadership
Ensayo final solucionde problemas
Lista de citejo para el trabajo de excel
Glc istanbul – forum
Studyshare
00 IntroduccióN Al Curso
Ad

Similar to Chapter 1 Presentation (20)

PPSX
Net framework session01
PPT
03 oo with-c-sharp
PDF
Lesson 2 Understanding Types And Usage In Dot Net
PPTX
SPF Getting Started - Console Program
PPTX
Getting Started - Console Program and Problem Solving
PPTX
Chapter 13 introduction to classes
PDF
(7) c sharp introduction_advanvced_features_part_ii
PPTX
21CS642 Module 2 Generics PPT.pptx VI SEM CSE
PDF
Introduction to c#
PDF
Introduction To Csharp
PPT
Introduction to csharp
PPT
Introduction to csharp
PPT
Introduction to csharp
PPTX
Visual Basic User Interface -IV
PDF
Object Oriented Programming notes provided
PPT
00-review.ppt
PPTX
Java Unit 2(Part 1)
DOCX
C questions
PPT
Object Oriented Programming In .Net
Net framework session01
03 oo with-c-sharp
Lesson 2 Understanding Types And Usage In Dot Net
SPF Getting Started - Console Program
Getting Started - Console Program and Problem Solving
Chapter 13 introduction to classes
(7) c sharp introduction_advanvced_features_part_ii
21CS642 Module 2 Generics PPT.pptx VI SEM CSE
Introduction to c#
Introduction To Csharp
Introduction to csharp
Introduction to csharp
Introduction to csharp
Visual Basic User Interface -IV
Object Oriented Programming notes provided
00-review.ppt
Java Unit 2(Part 1)
C questions
Object Oriented Programming In .Net

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars

Chapter 1 Presentation

  • 1. Chapter 1: Framework Fundamentals produced by BichTran
  • 2. Objectives Manage data by using the .NET Framework 2.0 system types. Implement .NET Framework interfaces Control interactions between components by using events and delegates
  • 3. Agenda Lesson 1: Using Value Types Lesson 2: Using Common Reference Types Lesson 3: Constructing Classes Lesson 4: Converting Between Types Question and answer Practice test
  • 4. Using Value Types Built-in types : sbyte – byte – short – int – uint – float long –double – decimal char – bool – date – none (Pointer to a memory address) Enumerations : - enum User-defined types: - struct ( Operators is new in .NET 2.0) struct Cycle { int _val, _min, _max; public Cycle (int min, int max) { _val = min; _min = min; _max = max;} public static Cycle operator +(Cycle arg1, int arg2) { arg1.Value += arg2; return arg1; } public static Cycle operator -(Cycle arg1, int arg2) { arg1.Value -= arg2; return arg1;} }
  • 5. Using Value Types (cont.) Use with new feature of Struct (operators) in .NET 2.0 Cycle degrees = new Cycle(0, 359); Cycle quarters = new Cycle(1, 4); for (int i = 0; i <= 8; i++) { degrees += 90; quarters += 1; Console.WriteLine(&quot;degrees = {0}, quarters = {1}&quot;, degrees, quarters); } In short, structure types is suitable for simple data, size less than 16 bytes, not be changed after creation, not be cast to a reference type Summary: Assigning value-type variables, the data is copied and stored on the stack. Value-types represent simple values, they have methods (as objects) The Nullable type is new in .NET 2.0. Case: use a variable as nullable when its value has not been assigned. Ex: a bool variable has not been assigned
  • 6. Using Common Reference Types There are about 2500 built-in reference types in the .NET Framework (not derived from System. ValueType ): Object: the most general type, any type can be converted to Object. String and StringBuilder: StringBuilder is more flexible than String Exception : unexpected events that interrupt normal execution of an assembly. Use following blocks in case catching exceptions: try {} catch (Exception ex) {} finally {} Tips: - Your own exceptions will be derived from System.ApplicationException - The runtime will execute only the first Catch block matching exception type. So order of Catch blocks should be from the most-specific to the least-specific . ,etc.
  • 7. Constructing Classes Inheritance: use inheritance to create new types based on existing ones. Interface: use interfaces to define a common set of members that must be implemented by related types. For example, the IComparable , IDisposable, IConvertible .etc. Partial class: use partial classes to split a class definition across multiple source files. Use: “ partial ”is preceded keyword “ class ” Generics (new in .NET 2.0) NET 1.0 and 1.1 did not support generics. With Generics Without Generics public class Gen<T, U> { public T t; public U u; public Gen(T _t, U _u) { t = _t; u = _u;} } public class Obj { public Object t; public Object u; public Obj(Object _t, Object _u) { t = _t; u = _u; } }
  • 8. Constructing Classes (cont.) With Generics Without Generics Gen<string, string> ga = new Gen<string, string>(&quot;Hello, &quot;, &quot;World!&quot;); string s = ga.t + ga.u; Gen<double, int> gb = new Gen<double, int>(10.125, 2005); double db = gb.t + gb.u; Obj oa = new Obj(&quot;Hello, &quot;, &quot;World!&quot;); string s = (string)oa.t + (string)oa.u); Obj ob = new Obj(10.125, 2005); double db = (double)ob.t + (int)ob.u); double db = (int)ob.t + (int)ob.u); // runtime exception
  • 9. Constructing Classes (cont.) Event: An event is a message sent by an object to signal the occurrence of an action. Delegate : A delegate is a class that can hold references to a methods which matches its signature. ( like method-pointer) public event MyEventHandler MyEvent; public delegate void MyEventHandler(object sender, EventArgs e); Raise event : MyEventHandler handler = MyEvent; EventArgs e = new EventArgs(); if (handler != null) { // Invokes the delegates. handler(this, e); } //C# checks to determine whether handler is null. Respond to the event: private void button1_Click(object sender, EventArgs e) {} button1.Click += new System.EventHandler(this.button1_Click);
  • 10. Constructing Classes (cont.) Attributes: Use attributes to describe assemblies, types, and members. For example : [Serializable] class ShoppingCartItem {….} Type Forwarding (thinking) Using attribute “TypeForwardedTo” to move a type from one class library to another using System.Runtime.CompilerServices; [assembly:TypeForwardedTo(typeof(DestLib.TypeA))]
  • 11. Converting Between Types Conversion: 2 kinds Widening Conversion : the range of the destination type is wider than that of the source type.(implicit conversion) Narrowing conversion: the range or precision of the source type exceeds that of the destination type, which usually requires explicit conversion. NOTE : Use TryParse, TryParseExact, and TryCast are new in .NET 2.0. Instead of attempting a parsing/conversion and catch the exception if it failed. Boxing and Unboxing Boxing converts a value type to a reference type. Unboxing converts a reference type to a value type. Unboxing Boxing object o = 123; int i = (int) o; int i = 123; object o = (object) i;
  • 13. Thanks for your attention