SlideShare a Scribd company logo
• 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 c#
Introduction to c#Introduction to c#
Introduction to c#singhadarsh
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpsarfarazali
 
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 c#
Introduction to c#Introduction to c#
Introduction to c#
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
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

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»QADay
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

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.