SlideShare a Scribd company logo
1 of 13
• Value Types and Reference Types
• Out Type
• Inheritance
• Static members
• Understanding Namespaces and Assemblies
• Casting Objects
• Partial Classes
• Generics
Three types of method parameters :

• Value
• Reference
• Out

int num = 10;
ProcessNumber(ref num);
Console.WriteLine(num);


private void ProcessNumber(ref int number)
{
number *= 2;
}
int num = 10;
 int doubled, tripled;
 ProcessNumber(num, out doubled, out tripled);




private void ProcessNumber(int number, out int doubled, out int tripled)
{
doubled = number * 2;
tripled = number * 3;
}
public class TaxableProduct : Product
{
private decimal taxRate = 1.15M;
public decimal TotalPrice
{
get
{
return (Price * taxRate);
}
}

public TaxableProduct(string name, decimal price, string
imageUrl) :
base(name, price, imageUrl)
{}
}
public class TaxableProduct : Product
{
// (Additional class code omitted for clarity.)
private static decimal taxRate = 1.15M;

// Now you can call TaxableProduct.TaxRate, even without an object.
public static decimal TaxRate
{
get
{ return taxRate; }
set
{ taxRate = value; }
}
}
Every piece of code in .NET exists inside a class type.
In turn, every class type exists inside a namespace.

Without namespaces, these types would all be grouped
into a single long and messy list.

namespace MyApp
{
public class Product
{
// Code goes here.
}
}
namespace MyCompany
   {
     namespace MyApp
     {
           public class Product
           { //code goes here
           }
     }
   }

   using MyCompany.MyApp;

   Consider the situation without importing a namespace:
MyCompany.MyApp.Product salesProduct = new MyCompany.MyApp.Product();
Assemblies are the physical files that contain compiled code.
Typically, assembly files have the extension .exe if they are stand-alone
applications or .dll if they’re reusable components.

An assembly can contain multiple namespaces. Conversely, more than
one assembly file can contain classes in the same namespace.

Technically, namespaces are a logical way to group classes.
Assemblies, however, are a physical package for distributing code.

Often, assemblies and namespaces have the same names. For
example, you’ll find the namespace System.Web in the assembly file
System.Web.dll.

However, this is a convenience, not a requirement. For example, the
basic types in the System namespace come from the mscorlib.dll
assembly.
•                            Product


                         TaxableProduct

TaxableProduct t1 = new TaxableProduct("Kitchen Garbage", 49.99M, "garbage.jpg");

    // Cast the TaxableProduct reference to a Product reference.
    Product p1 = t1;

    // This code generates a compile-time error.
    decimal TotalPrice = theProduct.TotalPrice;

    Correct way is :
    Product p1 = new TaxableProduct();
    TaxableProduct t1 = (TaxableProduct) p1;
This is wrong :
Product p1 = new Product();
TaxableProduct t1 = (TaxableProduct) p1;


Solution is check whether p1 is TaxableProduct then cast it

if (p1 is TaxableProduct)
{
TaxableProduct t1 = (TaxableProduct) p1;
}


Another way to type cast is use as keyword
TaxableProduct t1 = p1 as TaxableProduct;
Partial classes give you the ability to split a single class into more than
one C# source code (.cs) file.

Partial class behaves the same as a normal class. This means every
method, property, and variable you’ve defined in the class is available
everywhere, no matter which source file contains it.

When you compile the application, the compiler tracks down each piece
of the Product class and assembles it into a complete unit. It doesn’t
matter what you name the source code files, so long as you keep the
class name consistent.

Example:
Product class can be placed in two .cs file Product1.cs and Product2.cs
Generics allow you to create classes that are parameterized by type.
ArrayList products = new ArrayList();
// Add several Product objects.
products.Add(product1);
products.Add(product2);
products.Add(product3);
// Notice how you can still add other types to the ArrayList.
products.Add("This string doesn't belong here.");

// Instead create the List for storing Product objects.
List<Product> products = new List<Product>();
Now you can add only Product objects to the collection:
// Add several Product objects.
products.Add(product1);
products.Add(product2);
products.Add(product3);
// This line fails. In fact, it won't even compile.
products.Add("This string can't be inserted.");
At its simplest, object-oriented programming is the idea that
your code should be organized into separate classes.

If followed carefully, this approach leads to code that’s
easier to alter, enhance, debug, and reuse.

More Related Content

What's hot

Twig internals - Maksym MoskvychevTwig internals maksym moskvychev
Twig internals - Maksym MoskvychevTwig internals   maksym moskvychevTwig internals - Maksym MoskvychevTwig internals   maksym moskvychev
Twig internals - Maksym MoskvychevTwig internals maksym moskvychevDrupalCampDN
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NETmentorrbuddy
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Languageyht4ever
 
Linq And Its Impact On The.Net Framework
Linq And Its Impact On The.Net FrameworkLinq And Its Impact On The.Net Framework
Linq And Its Impact On The.Net Frameworkrushputin
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scalaKnoldus Inc.
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template libraryRahul Sharma
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in pythonKarin Lagesen
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guideTobias Schlitt
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryJoyjit Choudhury
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday lifeAndrea Iacono
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? EdurekaEdureka!
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8sumitbardhan
 

What's hot (18)

Twig internals - Maksym MoskvychevTwig internals maksym moskvychev
Twig internals - Maksym MoskvychevTwig internals   maksym moskvychevTwig internals - Maksym MoskvychevTwig internals   maksym moskvychev
Twig internals - Maksym MoskvychevTwig internals maksym moskvychev
 
Actionscript
ActionscriptActionscript
Actionscript
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
Linq And Its Impact On The.Net Framework
Linq And Its Impact On The.Net FrameworkLinq And Its Impact On The.Net Framework
Linq And Its Impact On The.Net Framework
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template library
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in python
 
List in java
List in javaList in java
List in java
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guide
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
 
Packages and Datastructures - Python
Packages and Datastructures - PythonPackages and Datastructures - Python
Packages and Datastructures - Python
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
Linq intro
Linq introLinq intro
Linq intro
 

Similar to Chapter 3 part2

Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console ProgramHock Leng PUAH
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
Functions and Modules.pptx
Functions and Modules.pptxFunctions and Modules.pptx
Functions and Modules.pptxAshwini Raut
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Ali Raza Zaidi
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpsarfarazali
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#singhadarsh
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185Mahmoud Samir Fayed
 

Similar to Chapter 3 part2 (20)

Csharp generics
Csharp genericsCsharp generics
Csharp generics
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
I x scripting
I x scriptingI x scripting
I x scripting
 
Functions and Modules.pptx
Functions and Modules.pptxFunctions and Modules.pptx
Functions and Modules.pptx
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185
 

More from application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

Chapter 3 part2

  • 1. • Value Types and Reference Types • Out Type • Inheritance • Static members • Understanding Namespaces and Assemblies • Casting Objects • Partial Classes • Generics
  • 2. Three types of method parameters : • Value • Reference • Out int num = 10; ProcessNumber(ref num); Console.WriteLine(num); private void ProcessNumber(ref int number) { number *= 2; }
  • 3. int num = 10; int doubled, tripled; ProcessNumber(num, out doubled, out tripled); private void ProcessNumber(int number, out int doubled, out int tripled) { doubled = number * 2; tripled = number * 3; }
  • 4. public class TaxableProduct : Product { private decimal taxRate = 1.15M; public decimal TotalPrice { get { return (Price * taxRate); } } public TaxableProduct(string name, decimal price, string imageUrl) : base(name, price, imageUrl) {} }
  • 5. public class TaxableProduct : Product { // (Additional class code omitted for clarity.) private static decimal taxRate = 1.15M; // Now you can call TaxableProduct.TaxRate, even without an object. public static decimal TaxRate { get { return taxRate; } set { taxRate = value; } } }
  • 6. Every piece of code in .NET exists inside a class type. In turn, every class type exists inside a namespace. Without namespaces, these types would all be grouped into a single long and messy list. namespace MyApp { public class Product { // Code goes here. } }
  • 7. namespace MyCompany { namespace MyApp { public class Product { //code goes here } } } using MyCompany.MyApp; Consider the situation without importing a namespace: MyCompany.MyApp.Product salesProduct = new MyCompany.MyApp.Product();
  • 8. Assemblies are the physical files that contain compiled code. Typically, assembly files have the extension .exe if they are stand-alone applications or .dll if they’re reusable components. An assembly can contain multiple namespaces. Conversely, more than one assembly file can contain classes in the same namespace. Technically, namespaces are a logical way to group classes. Assemblies, however, are a physical package for distributing code. Often, assemblies and namespaces have the same names. For example, you’ll find the namespace System.Web in the assembly file System.Web.dll. However, this is a convenience, not a requirement. For example, the basic types in the System namespace come from the mscorlib.dll assembly.
  • 9. Product TaxableProduct TaxableProduct t1 = new TaxableProduct("Kitchen Garbage", 49.99M, "garbage.jpg"); // Cast the TaxableProduct reference to a Product reference. Product p1 = t1; // This code generates a compile-time error. decimal TotalPrice = theProduct.TotalPrice; Correct way is : Product p1 = new TaxableProduct(); TaxableProduct t1 = (TaxableProduct) p1;
  • 10. This is wrong : Product p1 = new Product(); TaxableProduct t1 = (TaxableProduct) p1; Solution is check whether p1 is TaxableProduct then cast it if (p1 is TaxableProduct) { TaxableProduct t1 = (TaxableProduct) p1; } Another way to type cast is use as keyword TaxableProduct t1 = p1 as TaxableProduct;
  • 11. Partial classes give you the ability to split a single class into more than one C# source code (.cs) file. Partial class behaves the same as a normal class. This means every method, property, and variable you’ve defined in the class is available everywhere, no matter which source file contains it. When you compile the application, the compiler tracks down each piece of the Product class and assembles it into a complete unit. It doesn’t matter what you name the source code files, so long as you keep the class name consistent. Example: Product class can be placed in two .cs file Product1.cs and Product2.cs
  • 12. Generics allow you to create classes that are parameterized by type. ArrayList products = new ArrayList(); // Add several Product objects. products.Add(product1); products.Add(product2); products.Add(product3); // Notice how you can still add other types to the ArrayList. products.Add("This string doesn't belong here."); // Instead create the List for storing Product objects. List<Product> products = new List<Product>(); Now you can add only Product objects to the collection: // Add several Product objects. products.Add(product1); products.Add(product2); products.Add(product3); // This line fails. In fact, it won't even compile. products.Add("This string can't be inserted.");
  • 13. At its simplest, object-oriented programming is the idea that your code should be organized into separate classes. If followed carefully, this approach leads to code that’s easier to alter, enhance, debug, and reuse.