SlideShare a Scribd company logo
   A class is a construct that enables you to
    create your own custom types by grouping
    together variables of other types, methods
    and events.
   A class is like a blueprint. It defines the data
    and behavior of a type.
   Syntax for creating a class
      [attributes] [modifiers] class identifier [:base-list]
       { class-body }
   Ex:
      public class Customer { //Fields, properties, methods and
       events go here... }

                                                                Contd…
   The data and functions within a class are
    known as the class’s members.
   Data Members
      Data members are those members that contain the data for
       class – fields, constants and events.
      Data members can be static.
      Fields are any variables associated with the class.
      Events are class members that allow an object to notify a
       caller whenever something of interest occurs.
   Function Members
      Function members are those members that provide
       some functionality for manipulating the data in the
       class.
      These include methods, properties, constructors,
       finalizers, operators, and indexers.
   A struct type is a value type that can contain
    constructors, constants, fields, methods, properties,
    indexers, operators, events, and nested types.
   The declaration of a struct takes the following form:
      [attributes] [modifiers] struct identifier [:interfaces] {//body }

   Structs share most of the same syntax as classes,
    although structs are more limited than classes:
   Within a struct declaration, fields cannot be initialized
    unless they are declared as const or static.
   A struct cannot declare a default constructor (a
    constructor without parameters) or a destructor.
   Structs are value types and classes are
    reference types.
   Unlike classes, structs can be instantiated
    without using a new operator.
   Structs can declare constructors that have
    parameters.
   A struct cannot inherit from another struct or
    class, and it cannot be the base of a class. All
    structs inherit directly from
    System.ValueType, which inherits from
    System.Object.
   A struct can implement interfaces.
   A struct can be used as a nullable type and
    can be assigned a null value.
   A method is a code block that contains a series of
    statements.
   In C#, every executed instruction is performed in
    the context of a method.
   Declaring Methods
    ◦ Syntax
       [modifiers] return-type MethodName ([parameters])
         {
         //method body
         }




                                                           Contd…
   Passing Parameters to Methods
    ◦ Parameters can be passed into methods by reference or by value.
    ◦ In C#, all parameters are passed by value unless you specifically
      say otherwise.
   ref Parameters
    ◦ The ref keyword causes arguments to be passed by reference.
      The effect is that any changes to the parameter in the method
      will be reflected in that variable when control passes back to the
      calling method.
   out Parameters
    ◦ The out keyword on a method parameter causes a method to
      refer to the same variable that was passed into the method.
      Any changes made to the parameter in the method will be
      reflected in that variable when control passes back to the
      calling method.


                                                               Contd…
   Passing by Reference vs. Passing by Value

      When a value type is passed to a method, a copy is
       passed instead of the object itself. Therefore, changes
       to the argument have no effect on the original copy in
       the calling method. You can pass a value-type by
       reference by using the ref keyword.

      Reference types are passed by reference. When an
       object of a reference type is passed to a method, the
       reference points to the original object, not a copy.
       Changes made through this reference will therefore be
       reflected in the calling method.



                                                        Contd…
   Named Arguments
      Named arguments allow you to pass in parameters in
       any order.
   Optional Arguments
      Parameters can also be optional
      You must supply a default value for parameters that
       are optional
      The optional parameter(s) must be the last ones
       defined as well.
   C# supports method overloading – several
    versions of the method that have different
    signatures.
    ◦ To overload methods, you simply declare the methods with
      the same name but different number or types of
      parameters.
   A property is a member that provides a flexible
    mechanism to read, write, or compute the value of
    a private field.
   Properties can be used as if they are public data
    members, but they are actually special methods
    called accessors.
    ◦ Ex:
       private int _age;
       public int Age
       {
         get{return age;}
         set{age=value;}
       }
    ◦ We can have access modifiers for set and get accessors
   Whenever a class or struct is created, its constructor is called.
   A class or struct may have multiple constructors that take
    different arguments.
   Constructors enable the programmer to set default values,
    limit instantiation, and write code that is flexible and easy to
    read.
   If you do not provide a constructor for your object, C# will
    create one by default that instantiates the object and sets
    member variables to the default values.
   Static classes and structs can also have constructors.
   We can have private constructors




                                                             Contd…
   Static Constructors
        A static constructor is used to initialize any static data, or to perform
         a particular action that needs to be performed once only. It is called
         automatically before the first instance is created or any static
         members are referenced.
        A static constructor does not take access modifiers or have parameters.
        The user has no control on when the static constructor is executed in the
         program.

   Calling Constructors from Other Constructors
      A constructor can use the base keyword to call the constructor of
       a base class.
      Ex:
           public Manager() : base()
           { //Add further instructions here. }


                                                                       Contd…
   A constructor can invoke another constructor
    in the same object by using the this keyword.
   The readonly keyword is a modifier that you can
    use on fields.
   When a field declaration includes a readonly
    modifier, assignments to the fields introduced by
    the declaration can only occur as part of the
    declaration or in a constructor in the same class.
   Ex:
       class Age {
       readonly int _year; Age(int year)
       { _year = year; }
       void ChangeYear() { //_year = 1967; // Compile error if uncommented. }
       }
   Anonymous types provide a convenient way to
    encapsulate a set of read-only properties into a single
    object without having to explicitly define a type first.
   The type name is generated by the compiler and is not
    available at the source code level. The type of each
    property is inferred by the compiler.
   You create anonymous types by using the new operator
    together with an object initializer.
    ◦ Ex:
      var v = new { Amount = 108, Message = "Hello" };
   It is possible to split the definition of a class or a struct, an
    interface or a method over two or more source files. Each
    source file contains a section of the type or method
    definition, and all parts are combined when the application is
    compiled.
   To split a class definition, use the partial keyword modifier,
    as shown here:
        public partial class Employee
        {
        public void DoWork() { }
        }
        public partial class Employee
        {
        public void GoToLunch() { }
        }
   A static class is basically the same as a non-static
    class, but there is one difference: a static class
    cannot be instantiated.

   The following list provides the main features of a static class:
       Contains only static members.
       Cannot be instantiated.
       Is sealed.
       Cannot contain Instance Constructors.
   As indicated earlier, all .NET classes are ultimately
      derived from System.Object.
     System.Object Methods:
Equals(Object)      Determines whether the specified object is equal to the
                    current Object.

Finalize()          Allows an object to try to free resources and perform other
                    cleanup operations before it is reclaimed by garbage
                    collection.

GetHashCode()       Serves as a hash function for a particular type

MemberwiseClone()   Creates a shallow copy of the current Object.

ToString()          Returns a string that represents the current object.
   Extension methods enable you to "add" methods to
    existing types without creating a new derived type,
    recompiling, or otherwise modifying the original type.
   Extension methods are defined as static methods but
    are called by using instance method syntax.
   Their first parameter specifies which type the method
    operates on, and the parameter is preceded by the
    this modifier.
   Extension methods are only in scope when you
    explicitly import the namespace into your source
    code with a using directive.

More Related Content

What's hot

Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
M Vishnuvardhan Reddy
 
Java Basics
Java BasicsJava Basics
Java Basics
Emprovise
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Oops in vb
Oops in vbOops in vb
Oops in vb
Dalwin INDIA
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
Riaj Uddin Mahi
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
Prem Kumar Badri
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Madishetty Prathibha
 
C++ training
C++ training C++ training
C++ training
PL Sharma
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
kjkleindorfer
 
Generics in java
Generics in javaGenerics in java
Generics in java
suraj pandey
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
saranuru
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
Java
JavaJava

What's hot (20)

Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Classes2
Classes2Classes2
Classes2
 
My c++
My c++My c++
My c++
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
C++ training
C++ training C++ training
C++ training
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Java
JavaJava
Java
 

Similar to Objects and Types C#

Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
C# program structure
C# program structureC# program structure
C++
C++C++
C++
C++C++
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
NicheTech Com. Solutions Pvt. Ltd.
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
Duong Thanh
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
ismartshanker1
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
MohammedOmer401579
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
Eng Teong Cheah
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
megersaoljira
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
VB.net
VB.netVB.net
VB.net
PallaviKadam
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
Tabassum Ghulame Mustafa
 
C# interview
C# interviewC# interview
C# interview
Thomson Reuters
 

Similar to Objects and Types C# (20)

Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
C# program structure
C# program structureC# program structure
C# program structure
 
C++
C++C++
C++
 
C++
C++C++
C++
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
C# concepts
C# conceptsC# concepts
C# concepts
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
VB.net
VB.netVB.net
VB.net
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
C# interview
C# interviewC# interview
C# interview
 

More from Raghuveer Guthikonda (9)

C# String
C# StringC# String
C# String
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
Operators & Casts
Operators & CastsOperators & Casts
Operators & Casts
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Generics C#
Generics C#Generics C#
Generics C#
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Regex in C#
Regex in C#Regex in C#
Regex in C#
 

Recently uploaded

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
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
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
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
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
Safe Software
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
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
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
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
CatarinaPereira64715
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

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...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
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
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
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
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
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
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Objects and Types C#

  • 1.
  • 2. A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events.  A class is like a blueprint. It defines the data and behavior of a type.  Syntax for creating a class  [attributes] [modifiers] class identifier [:base-list] { class-body }  Ex:  public class Customer { //Fields, properties, methods and events go here... } Contd…
  • 3. The data and functions within a class are known as the class’s members.  Data Members  Data members are those members that contain the data for class – fields, constants and events.  Data members can be static.  Fields are any variables associated with the class.  Events are class members that allow an object to notify a caller whenever something of interest occurs.  Function Members  Function members are those members that provide some functionality for manipulating the data in the class.  These include methods, properties, constructors, finalizers, operators, and indexers.
  • 4. A struct type is a value type that can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types.  The declaration of a struct takes the following form:  [attributes] [modifiers] struct identifier [:interfaces] {//body }  Structs share most of the same syntax as classes, although structs are more limited than classes:  Within a struct declaration, fields cannot be initialized unless they are declared as const or static.  A struct cannot declare a default constructor (a constructor without parameters) or a destructor.
  • 5. Structs are value types and classes are reference types.  Unlike classes, structs can be instantiated without using a new operator.  Structs can declare constructors that have parameters.  A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from System.ValueType, which inherits from System.Object.  A struct can implement interfaces.  A struct can be used as a nullable type and can be assigned a null value.
  • 6. A method is a code block that contains a series of statements.  In C#, every executed instruction is performed in the context of a method.  Declaring Methods ◦ Syntax [modifiers] return-type MethodName ([parameters]) { //method body } Contd…
  • 7. Passing Parameters to Methods ◦ Parameters can be passed into methods by reference or by value. ◦ In C#, all parameters are passed by value unless you specifically say otherwise.  ref Parameters ◦ The ref keyword causes arguments to be passed by reference. The effect is that any changes to the parameter in the method will be reflected in that variable when control passes back to the calling method.  out Parameters ◦ The out keyword on a method parameter causes a method to refer to the same variable that was passed into the method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method. Contd…
  • 8. Passing by Reference vs. Passing by Value  When a value type is passed to a method, a copy is passed instead of the object itself. Therefore, changes to the argument have no effect on the original copy in the calling method. You can pass a value-type by reference by using the ref keyword.  Reference types are passed by reference. When an object of a reference type is passed to a method, the reference points to the original object, not a copy. Changes made through this reference will therefore be reflected in the calling method. Contd…
  • 9. Named Arguments  Named arguments allow you to pass in parameters in any order.  Optional Arguments  Parameters can also be optional  You must supply a default value for parameters that are optional  The optional parameter(s) must be the last ones defined as well.
  • 10. C# supports method overloading – several versions of the method that have different signatures. ◦ To overload methods, you simply declare the methods with the same name but different number or types of parameters.
  • 11. A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field.  Properties can be used as if they are public data members, but they are actually special methods called accessors. ◦ Ex: private int _age; public int Age { get{return age;} set{age=value;} } ◦ We can have access modifiers for set and get accessors
  • 12. Whenever a class or struct is created, its constructor is called.  A class or struct may have multiple constructors that take different arguments.  Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.  If you do not provide a constructor for your object, C# will create one by default that instantiates the object and sets member variables to the default values.  Static classes and structs can also have constructors.  We can have private constructors Contd…
  • 13. Static Constructors  A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced.  A static constructor does not take access modifiers or have parameters.  The user has no control on when the static constructor is executed in the program.  Calling Constructors from Other Constructors  A constructor can use the base keyword to call the constructor of a base class.  Ex: public Manager() : base() { //Add further instructions here. } Contd…
  • 14. A constructor can invoke another constructor in the same object by using the this keyword.
  • 15. The readonly keyword is a modifier that you can use on fields.  When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.  Ex: class Age { readonly int _year; Age(int year) { _year = year; } void ChangeYear() { //_year = 1967; // Compile error if uncommented. } }
  • 16. Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.  The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.  You create anonymous types by using the new operator together with an object initializer. ◦ Ex:  var v = new { Amount = 108, Message = "Hello" };
  • 17. It is possible to split the definition of a class or a struct, an interface or a method over two or more source files. Each source file contains a section of the type or method definition, and all parts are combined when the application is compiled.  To split a class definition, use the partial keyword modifier, as shown here: public partial class Employee { public void DoWork() { } } public partial class Employee { public void GoToLunch() { } }
  • 18. A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated.  The following list provides the main features of a static class:  Contains only static members.  Cannot be instantiated.  Is sealed.  Cannot contain Instance Constructors.
  • 19. As indicated earlier, all .NET classes are ultimately derived from System.Object.  System.Object Methods: Equals(Object) Determines whether the specified object is equal to the current Object. Finalize() Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. GetHashCode() Serves as a hash function for a particular type MemberwiseClone() Creates a shallow copy of the current Object. ToString() Returns a string that represents the current object.
  • 20. Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.  Extension methods are defined as static methods but are called by using instance method syntax.  Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier.  Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.