SlideShare a Scribd company logo
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com
For video visit
www.dotnetvideotutorial.com
Methods
Passing
value types
By Value
By
Reference
Passing
reference
types
By Value
By
Reference
Agenda
Features
Variable
arguments
Named
arguments
Optional
parameters
Methods
 A method is a code block containing a series of statements.
 Methods are declared within a class or struct by specifying
 Access Modifier
 Other Modifiers
 Return value
 Name of the method
 Method parameters.
public static int add(int no1, int no2)
{
}
www.dotnetvideotutorial.com
Possible Combinations
• Method without parameter and no
return value
void fun1()
• Method with parameter and no return
value
void fun2(string name)
• Method with parameter and return
value
int fun3(int no1, int no2)
• Method without parameter but with
return value
string fun4()
Method without parameter and No return value
static void Main(string[] args)
{
greet();
Console.ReadKey();
}
static void greet()
{
Console.WriteLine("Hello");
}
www.dotnetvideotutorial.com
static void Main(string[] args)
{
greet("Mr. Anderson");
Console.ReadKey();
}
static void greet(string name)
{
Console.WriteLine("Hello " + name);
}
Method with Parameters but No Return value
Mr. Anderson
name
www.dotnetvideotutorial.com
Method With Parameters and Return value
static void Main(string[] args)
{
int no1 = 10, no2 = 20;
int result = add(no1, no2);
Console.WriteLine("Result = {0}", result);
Console.ReadKey();
}
static int add(int no1, int no2)
{
int result = no1 + no2;
return result;
}
no1
10
no2
20
no1
10
no2
20
result
30
result
30
www.dotnetvideotutorial.com
Compact Format
static void Main(string[] args)
{
Console.WriteLine(add(25,50));
}
static int add(int no1, int no2)
{
return no1 + no2;
}
no1
25
no2
50
www.dotnetvideotutorial.com
Fn without Parameter but with return value
static void Main(string[] args)
{
Console.WriteLine(GetTime());
Console.ReadKey();
}
static string GetTime()
{
string time = DateTime.Now.ToShortTimeString();
return time;
}
www.dotnetvideotutorial.com
 ref and out keyword used to pass arguments by reference
 ref: to pass references of initialized variables
 out: to pass references of uninitialized variables
 value type as well as reference type can be passed by
reference
Passing References
www.dotnetvideotutorial.com
static void Main(string[] args)
{
int no1 = 25, no2 = 50;
Console.WriteLine("Before swaping: no1 = {0}, no2 = {1}", no1, no2);
Swap(ref no1, ref no2);
Console.WriteLine("After swaping: no1 = {0}, no2 = {1}", no1, no2);
Console.ReadKey();
}
static void Swap(ref int no1,ref int no2)
{
int temp = no1;
no1 = no2;
no2 = temp;
}
ref keyword
25
no1
5420
50
no2
5424
5420
no1
5424
no2
25
temp
50 25
www.dotnetvideotutorial.com
out keyword
static void Main(string[] args)
{
float radius, area, circumference;
Console.WriteLine("Enter Radius of Circle: ");
radius = Convert.ToInt32(Console.ReadLine());
Calculate(radius, out area, out circumference);
Console.WriteLine("Area = " + area);
Console.WriteLine("Circumference = " + circumference);
}
static void Calculate(float radius, out float area, out float circumference)
{
const float pi = 3.14f;
area = 2 * pi * radius;
circumference = pi * radius * radius;
}
radius
5420
5
area
5424
circum
5428
78.5
radius
5
area
5424
circum
5428
31.4
www.dotnetvideotutorial.com
Passing Reference Types
 Reference type can be passed by value as well by reference
 If passed by value - content of object reference is passed
 If passed by reference - reference of object reference is
passed
5028
2000 5028
obj
www.dotnetvideotutorial.com
Passing string by value
static void Main(string[] args)
{
string str = "Milkyway";
Console.WriteLine("str = " + str);
ChangeString(str);
Console.WriteLine("nstr = " + str);
}
static void ChangeString(string str)
{
Console.WriteLine("nstr = " + str);
str = "Andromeda";
Console.WriteLine("nstr = " + str);
}
5028 Milkyway
Andromeda
5028
5028
6252
6252
str
str
www.dotnetvideotutorial.com
Passing string by reference
static void Main(string[] args)
{
string str = "Milkyway";
Console.WriteLine("str = " + str);
ChangeString(ref str);
Console.WriteLine("nstr = " + str);
Console.ReadKey();
}
static void ChangeString(ref string str)
{
Console.WriteLine("nstr = " + str);
str = "Andromeda";
Console.WriteLine("nstr = " + str);
}
5028 Milkyway
Andromeda
5028
6252
6252
2020
2020
str
str
www.dotnetvideotutorial.com
Passing Array by value
static void Main(string[] args)
{
int[] marks = new int[] { 10, 20, 30 };
Console.WriteLine(marks[0]);
ChangeMarks(marks);
Console.WriteLine(marks[0]);
}
static void ChangeMarks(int[] marks)
{
Console.WriteLine(marks[0]);
marks[0] = 70;
Console.WriteLine(marks[0]);
}
5028
5028
10 20 30
5028
marks
marks
70
www.dotnetvideotutorial.com
Flexibility
Variable
Arguments
Named
Arguments
Optional
Parameters
Passing variable number of arguments
static void Main(string[] args)
{
Console.Write("Humans : ");
printNames("Neo", "Trinity", "Morphious", "Seroph");
Console.Write("Programs : ");
printNames("Smith", "Oracle");
}
static void printNames(params string[] names)
{
foreach (string n in names)
{
Console.Write(n + " ");
}
Console.WriteLine();
}
www.dotnetvideotutorial.com
Named Arguments
static void Main(string[] args)
{
int area1 = CalculateArea(width:10,height:15);
Console.WriteLine(area1);
int area2 = CalculateArea(height: 8, width: 4);
Console.WriteLine(area2);
}
static int CalculateArea(int width, int height)
{
return width * height;
}
www.dotnetvideotutorial.com
Optional Parameters
static void Main(string[] args)
{
Score(30, 70, 60, 80);
Score(30, 70, 60);
Score(30, 70);
}
static void Score(int m1,int m2,int m3 = 50,int m4 = 30)
{
Console.WriteLine(m1 + m2 + m3 + m4);
}
www.dotnetvideotutorial.com
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com

More Related Content

What's hot

Overview of MONOMI
Overview of MONOMIOverview of MONOMI
Overview of MONOMI
Mateus S. H. Cruz
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
Syntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - MindbowserSyntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - Mindbowser
Mindbowser Inc
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
Mayank Bhatt
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
Megha V
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
Mateus S. H. Cruz
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
Megha V
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
Muhammad Muzammal
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
Harish Gyanani
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
Dhiviya Rose
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Meghaj Mallick
 
Chapter 2 Method in Java OOP
Chapter 2   Method in Java OOPChapter 2   Method in Java OOP
Chapter 2 Method in Java OOP
Khirulnizam Abd Rahman
 
Static-talk
Static-talkStatic-talk
Static-talkgiunti
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
IoT Code Lab
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
Harry Potter
 

What's hot (20)

Overview of MONOMI
Overview of MONOMIOverview of MONOMI
Overview of MONOMI
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
Syntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - MindbowserSyntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - Mindbowser
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
Inverted Index Based Multi-Keyword Public-key Searchable Encryption with Stro...
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Chapter 2 Method in Java OOP
Chapter 2   Method in Java OOPChapter 2   Method in Java OOP
Chapter 2 Method in Java OOP
 
String functions in C
String functions in CString functions in C
String functions in C
 
Static-talk
Static-talkStatic-talk
Static-talk
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 

Viewers also liked

L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Sql
SqlSql
Sql
ftz 420
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
Database design
Database designDatabase design
Database design
Dhani Ahmad
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Processmussawir20
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
Stephen Colebourne
 
Value Engineering And Value Analysis
Value Engineering And Value AnalysisValue Engineering And Value Analysis
Value Engineering And Value Analysisthombremahesh
 

Viewers also liked (7)

L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Sql
SqlSql
Sql
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Database design
Database designDatabase design
Database design
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Value Engineering And Value Analysis
Value Engineering And Value AnalysisValue Engineering And Value Analysis
Value Engineering And Value Analysis
 

Similar to Methods

ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
Badoo Development
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия Swift
CocoaHeads
 
Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Feature
xcoda
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
Jay Patel
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
Svetlin Nakov
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
Prem Kumar Badri
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
Bhushan Mulmule
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
 
Codejunk Ignitesd
Codejunk IgnitesdCodejunk Ignitesd
Codejunk Ignitesd
carlmanaster
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programmingdaotuan85
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
PRN USM
 
14 initialization & cleanup
14   initialization & cleanup14   initialization & cleanup
14 initialization & cleanupdhrubo kayal
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
strikr .
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
Sónia
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smells
Paul Nguyen
 

Similar to Methods (20)

ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия Swift
 
Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Feature
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
Codejunk Ignitesd
Codejunk IgnitesdCodejunk Ignitesd
Codejunk Ignitesd
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
14 initialization & cleanup
14   initialization & cleanup14   initialization & cleanup
14 initialization & cleanup
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
 
Pointers.pdf
Pointers.pdfPointers.pdf
Pointers.pdf
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smells
 

More from Bhushan Mulmule

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
Bhushan Mulmule
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
Bhushan Mulmule
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
Bhushan Mulmule
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
Bhushan Mulmule
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Bhushan Mulmule
 
Inheritance
InheritanceInheritance
Inheritance
Bhushan Mulmule
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Bhushan Mulmule
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
Bhushan Mulmule
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
Bhushan Mulmule
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
Bhushan Mulmule
 

More from Bhushan Mulmule (15)

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
 

Recently uploaded

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
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
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
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
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
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
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 

Recently uploaded (20)

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
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
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
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
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
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...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 

Methods

  • 3. Methods Passing value types By Value By Reference Passing reference types By Value By Reference Agenda Features Variable arguments Named arguments Optional parameters
  • 4. Methods  A method is a code block containing a series of statements.  Methods are declared within a class or struct by specifying  Access Modifier  Other Modifiers  Return value  Name of the method  Method parameters. public static int add(int no1, int no2) { } www.dotnetvideotutorial.com
  • 5. Possible Combinations • Method without parameter and no return value void fun1() • Method with parameter and no return value void fun2(string name) • Method with parameter and return value int fun3(int no1, int no2) • Method without parameter but with return value string fun4()
  • 6. Method without parameter and No return value static void Main(string[] args) { greet(); Console.ReadKey(); } static void greet() { Console.WriteLine("Hello"); } www.dotnetvideotutorial.com
  • 7. static void Main(string[] args) { greet("Mr. Anderson"); Console.ReadKey(); } static void greet(string name) { Console.WriteLine("Hello " + name); } Method with Parameters but No Return value Mr. Anderson name www.dotnetvideotutorial.com
  • 8. Method With Parameters and Return value static void Main(string[] args) { int no1 = 10, no2 = 20; int result = add(no1, no2); Console.WriteLine("Result = {0}", result); Console.ReadKey(); } static int add(int no1, int no2) { int result = no1 + no2; return result; } no1 10 no2 20 no1 10 no2 20 result 30 result 30 www.dotnetvideotutorial.com
  • 9. Compact Format static void Main(string[] args) { Console.WriteLine(add(25,50)); } static int add(int no1, int no2) { return no1 + no2; } no1 25 no2 50 www.dotnetvideotutorial.com
  • 10. Fn without Parameter but with return value static void Main(string[] args) { Console.WriteLine(GetTime()); Console.ReadKey(); } static string GetTime() { string time = DateTime.Now.ToShortTimeString(); return time; } www.dotnetvideotutorial.com
  • 11.  ref and out keyword used to pass arguments by reference  ref: to pass references of initialized variables  out: to pass references of uninitialized variables  value type as well as reference type can be passed by reference Passing References www.dotnetvideotutorial.com
  • 12. static void Main(string[] args) { int no1 = 25, no2 = 50; Console.WriteLine("Before swaping: no1 = {0}, no2 = {1}", no1, no2); Swap(ref no1, ref no2); Console.WriteLine("After swaping: no1 = {0}, no2 = {1}", no1, no2); Console.ReadKey(); } static void Swap(ref int no1,ref int no2) { int temp = no1; no1 = no2; no2 = temp; } ref keyword 25 no1 5420 50 no2 5424 5420 no1 5424 no2 25 temp 50 25 www.dotnetvideotutorial.com
  • 13. out keyword static void Main(string[] args) { float radius, area, circumference; Console.WriteLine("Enter Radius of Circle: "); radius = Convert.ToInt32(Console.ReadLine()); Calculate(radius, out area, out circumference); Console.WriteLine("Area = " + area); Console.WriteLine("Circumference = " + circumference); } static void Calculate(float radius, out float area, out float circumference) { const float pi = 3.14f; area = 2 * pi * radius; circumference = pi * radius * radius; } radius 5420 5 area 5424 circum 5428 78.5 radius 5 area 5424 circum 5428 31.4 www.dotnetvideotutorial.com
  • 14. Passing Reference Types  Reference type can be passed by value as well by reference  If passed by value - content of object reference is passed  If passed by reference - reference of object reference is passed 5028 2000 5028 obj www.dotnetvideotutorial.com
  • 15. Passing string by value static void Main(string[] args) { string str = "Milkyway"; Console.WriteLine("str = " + str); ChangeString(str); Console.WriteLine("nstr = " + str); } static void ChangeString(string str) { Console.WriteLine("nstr = " + str); str = "Andromeda"; Console.WriteLine("nstr = " + str); } 5028 Milkyway Andromeda 5028 5028 6252 6252 str str www.dotnetvideotutorial.com
  • 16. Passing string by reference static void Main(string[] args) { string str = "Milkyway"; Console.WriteLine("str = " + str); ChangeString(ref str); Console.WriteLine("nstr = " + str); Console.ReadKey(); } static void ChangeString(ref string str) { Console.WriteLine("nstr = " + str); str = "Andromeda"; Console.WriteLine("nstr = " + str); } 5028 Milkyway Andromeda 5028 6252 6252 2020 2020 str str www.dotnetvideotutorial.com
  • 17. Passing Array by value static void Main(string[] args) { int[] marks = new int[] { 10, 20, 30 }; Console.WriteLine(marks[0]); ChangeMarks(marks); Console.WriteLine(marks[0]); } static void ChangeMarks(int[] marks) { Console.WriteLine(marks[0]); marks[0] = 70; Console.WriteLine(marks[0]); } 5028 5028 10 20 30 5028 marks marks 70 www.dotnetvideotutorial.com
  • 19. Passing variable number of arguments static void Main(string[] args) { Console.Write("Humans : "); printNames("Neo", "Trinity", "Morphious", "Seroph"); Console.Write("Programs : "); printNames("Smith", "Oracle"); } static void printNames(params string[] names) { foreach (string n in names) { Console.Write(n + " "); } Console.WriteLine(); } www.dotnetvideotutorial.com
  • 20. Named Arguments static void Main(string[] args) { int area1 = CalculateArea(width:10,height:15); Console.WriteLine(area1); int area2 = CalculateArea(height: 8, width: 4); Console.WriteLine(area2); } static int CalculateArea(int width, int height) { return width * height; } www.dotnetvideotutorial.com
  • 21. Optional Parameters static void Main(string[] args) { Score(30, 70, 60, 80); Score(30, 70, 60); Score(30, 70); } static void Score(int m1,int m2,int m3 = 50,int m4 = 30) { Console.WriteLine(m1 + m2 + m3 + m4); } www.dotnetvideotutorial.com