I have been writing a lot about advanced topics like MVC, Entity Framework, Repository Patterns etc., my priority always remains to cover the topic as a whole, so that a reader do not have to search for missing links anywhere else. My this article will cover almost every OOPS concept that a novice/beginner developer hunt for, and not only beginners, the article’s purpose is to be helpful to experience professionals also who need to sometimes brush-up their concepts or who prepare for interviews .
Old Java lectures by my teacher Karim Zebari at Software Department College of Engineering University of Salahaddin-Erbil. The topics are:
- Multithreading
- Security in Java
- Java Beans
- Internationalization
- Java Servlets
- Java Server Pages
- Database access in Java
- More GUI Components & Printing
- Remote Method Invocation (RMI)
- Java Collections Framework
Old Java lectures by my teacher Karim Zebari at Software Department College of Engineering University of Salahaddin-Erbil. The topics are:
- Multithreading
- Security in Java
- Java Beans
- Internationalization
- Java Servlets
- Java Server Pages
- Database access in Java
- More GUI Components & Printing
- Remote Method Invocation (RMI)
- Java Collections Framework
Everything about OOPs (Object-oriented programming) in this slide we cover the all details about object-oriented programming using C++. we also discussed why C++ is called a subset of C.
The skeletal implementation pattern is a software design pattern consisting of defining an abstract class that provides a partial interface implementation. However, since Java allows only single class inheritance, if implementers decide to extend a skeletal implementation, they will not be allowed to extend any other class. Also, discovering the skeletal implementation may require a global analysis.
Java 8 enhanced interfaces alleviate these problems by allowing interfaces to contain (default) method implementations, which implementers inherit. Java classes are then free to extend a different class, and a separate abstract class is no longer needed; developers considering implementing an interface need only examine the interface itself.
In this talk, I will argue that both these benefits improve software modularity, and I will discuss our ongoing work in developing an automated refactoring tool that would assist developers in taking advantage of the enhanced interface feature for their legacy Java software.
Raffi Khatchadourian is an Assistant Professor in the Department of Computer Systems Technology (CST) at New York City College of Technology (NYCCT) of the City University of New York (CUNY) and an Open Educational Resources (OER) Fellow for the Spring 2016 semester. His research is centered on techniques for automated software evolution, particularly those related to automated refactoring and source code recommendation systems. His goal is to ease the burden associated with correctly and efficiently evolving large and complex software by providing automated tools that can be easily used by developers.
Raffi received his MS and PhD degrees in Computer Science from Ohio State University and his BS degree in Computer Science from Monmouth University in New Jersey. Prior to joining City Tech, he was a Software Engineer at Apple, Inc. in Cupertino, California, where he worked on Digital Rights Management (DRM) for iTunes, iBooks, and the App store. He also developed distributed software that tested various features of iPhones, iPads, and iPods.
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
Everything about OOPs (Object-oriented programming) in this slide we cover the all details about object-oriented programming using C++. we also discussed why C++ is called a subset of C.
The skeletal implementation pattern is a software design pattern consisting of defining an abstract class that provides a partial interface implementation. However, since Java allows only single class inheritance, if implementers decide to extend a skeletal implementation, they will not be allowed to extend any other class. Also, discovering the skeletal implementation may require a global analysis.
Java 8 enhanced interfaces alleviate these problems by allowing interfaces to contain (default) method implementations, which implementers inherit. Java classes are then free to extend a different class, and a separate abstract class is no longer needed; developers considering implementing an interface need only examine the interface itself.
In this talk, I will argue that both these benefits improve software modularity, and I will discuss our ongoing work in developing an automated refactoring tool that would assist developers in taking advantage of the enhanced interface feature for their legacy Java software.
Raffi Khatchadourian is an Assistant Professor in the Department of Computer Systems Technology (CST) at New York City College of Technology (NYCCT) of the City University of New York (CUNY) and an Open Educational Resources (OER) Fellow for the Spring 2016 semester. His research is centered on techniques for automated software evolution, particularly those related to automated refactoring and source code recommendation systems. His goal is to ease the burden associated with correctly and efficiently evolving large and complex software by providing automated tools that can be easily used by developers.
Raffi received his MS and PhD degrees in Computer Science from Ohio State University and his BS degree in Computer Science from Monmouth University in New Jersey. Prior to joining City Tech, he was a Software Engineer at Apple, Inc. in Cupertino, California, where he worked on Digital Rights Management (DRM) for iTunes, iBooks, and the App store. He also developed distributed software that tested various features of iPhones, iPads, and iPods.
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
We've all seen the big "macro" features in .NET, this presentation is to give praise to the "Little Wonders" of .NET -- those little items in the framework that make life as a developer that much easier!
it describes the main concepts of object oriented programming
For more posts : http://comsciguide.blogspot.com/
For full playlist of Interview puzzles videos : https://www.youtube.com/playlist?list=PL3v9ipJOEEPfI4zt4ExamGJwndkvg0SFc
24 standard interview puzzles: https://www.youtube.com/playlist?list=PL3v9ipJOEEPefIF4nscYOobim1iRBJTjw
Aptitude training playlist link : https://www.youtube.com/playlist?list=PL3v9ipJOEEPfumKHa02HWjCfPvGQiPZiG
for C and C++ questions, that are asked in the interviews, go through the posts in the link : http://comsciguide.blogspot.com/
for more videos, my youtube channel : https://www.youtube.com/channel/UCvMy2V7gYW7VR2WgyvLj3-A
C++ is an object-oriented programming language developed by Bjarne Stroustrup at AT&T Bell Lab in the year 1980. Initially it was named “C with classes” but later in 1983 the name changed to C++. It is an extension of C with..
Polymorphism is the ability of an object to take more than one forms. It is one of the important concept of object-oriented programming language. JAVA is object-oriented programming language which support the concept of polymorphisms.
Alternatively, it is defined as the ability of a reference variable to change behavior according to what object instance it is holding.
This article is about aspect oriented programming (aop) in spring. the related example of an application with aop support is in the following address :
https://github.com/ghorbanihamid/SpringBoot_AOP_JPA_Example
NicheTech is the best mobile development company in Ahmedabad,
We are providing iOS Live Project Training Ahmedabad, We are offering iOS Training Ahmedabad.
Get the best iOS Live Project Training Ahmedabad .
iOS Live Project Training Ahmedabad, iPhone Live Project Training Ahmedabad, iPhone classes Ahmedabad, iPhone Course Ahmedabad
iOS Live Project Ahmedabad:- http://liveprojecttraining.in/
LESSON 4: INTRODUCING FUNCTIONS AND MODULAR DESIGN
Learn about Functions in Python. Advantages and disadvantages of functions. Introduction to Modular design. Local and Global Variables and their use. Passing parameters. What are arguments? Big questions: Evolution vs Intelligent design in light of functions (and modular design). A closer look at Robotics and advances in this field. Challenges and tasks including with solutions. Suggested research/HW and YouTube video recommendations. A note on Python’s built in functions.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Welocme to ViralQR, your best QR code generator.ViralQR
Welcome to ViralQR, your best QR code generator available on the market!
At ViralQR, we design static and dynamic QR codes. Our mission is to make business operations easier and customer engagement more powerful through the use of QR technology. Be it a small-scale business or a huge enterprise, our easy-to-use platform provides multiple choices that can be tailored according to your company's branding and marketing strategies.
Our Vision
We are here to make the process of creating QR codes easy and smooth, thus enhancing customer interaction and making business more fluid. We very strongly believe in the ability of QR codes to change the world for businesses in their interaction with customers and are set on making that technology accessible and usable far and wide.
Our Achievements
Ever since its inception, we have successfully served many clients by offering QR codes in their marketing, service delivery, and collection of feedback across various industries. Our platform has been recognized for its ease of use and amazing features, which helped a business to make QR codes.
Our Services
At ViralQR, here is a comprehensive suite of services that caters to your very needs:
Static QR Codes: Create free static QR codes. These QR codes are able to store significant information such as URLs, vCards, plain text, emails and SMS, Wi-Fi credentials, and Bitcoin addresses.
Dynamic QR codes: These also have all the advanced features but are subscription-based. They can directly link to PDF files, images, micro-landing pages, social accounts, review forms, business pages, and applications. In addition, they can be branded with CTAs, frames, patterns, colors, and logos to enhance your branding.
Pricing and Packages
Additionally, there is a 14-day free offer to ViralQR, which is an exceptional opportunity for new users to take a feel of this platform. One can easily subscribe from there and experience the full dynamic of using QR codes. The subscription plans are not only meant for business; they are priced very flexibly so that literally every business could afford to benefit from our service.
Why choose us?
ViralQR will provide services for marketing, advertising, catering, retail, and the like. The QR codes can be posted on fliers, packaging, merchandise, and banners, as well as to substitute for cash and cards in a restaurant or coffee shop. With QR codes integrated into your business, improve customer engagement and streamline operations.
Comprehensive Analytics
Subscribers of ViralQR receive detailed analytics and tracking tools in light of having a view of the core values of QR code performance. Our analytics dashboard shows aggregate views and unique views, as well as detailed information about each impression, including time, device, browser, and estimated location by city and country.
So, thank you for choosing ViralQR; we have an offer of nothing but the best in terms of QR code services to meet business diversity!
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile Time Polymorphism)
1. OOP (Object Oriented Programming) with
C#: Early Binding/Compile Time
Polymorphism. –by Akhil Mittal
Table of Contents:
Table of Contents: _________________________________________________________________________________1
Introduction: _____________________________________________________________________________________1
Pre-requisites: ____________________________________________________________________________________2
OOPS: ___________________________________________________________________________________________2
What are OOP Concepts? ___________________________________________________________________________2
Polymorphism:____________________________________________________________________________________3
Method Overloading or Early Binding or Compile Time Polymorphism:______________________________________3
Role of Params Parameter in Polymorphism: __________________________________________________________6
Conclusion:______________________________________________________________________________________17
About Author __________________________________________________________________________________18
Introduction:
I have been writing a lot about advanced topics like MVC, Entity Framework, Repository Patterns etc., my
priority always remains to cover the topic as a whole, so that a reader do not have to search for missing links
anywhere else. My this article will cover almost every OOPS concept that a novice/beginner developer hunt
for, and not only beginners, the article’s purpose is to be helpful to experience professionals also who need to
sometimes brush-up their concepts or who prepare for interviews .
I will take the topics in a manner that we cover them in a simple straight way taking snippets as example
wherever needed. We’ll take C# as our programming language throughout our readings.
We’ll play with tricky questions and not go for enough theory. For theory you can refer MSDN.
2. Pre-requisites:
Since this is the first part of the series, my readers should have basic knowledge of C# and should be aware of
OOP concepts and terminology.
OOPS:
1. What is OOPS and what is advantage of OOP?
OOP stands for "Object-Oriented Programming." Remember its OOP not OOPS,’S’ may stand for
system, synopsis, structure etc. It is a programming approach entirely based on objects, instead of just
functions and procedures like in procedural languages. It is like a programming language model
organized around objects rather than "actions" and data rather than logic. An "object" in an OOP
language refers to a specific type, or "instance," of a class. Each object has a structure exactly similar to
other objects in a class, but can have individual properties/values. An object can also invoke methods,
specific to that object
OOP makes it easier for developers to structure and organize software programs. Individual objects can
be modified without affecting other aspects of the program therefore it is also easier to update and
change programs written in object-oriented languages. Since the nature of software programs have
grown larger over the years, OOP has made developing these large programs more manageable and
readable.
What are OOP Concepts?
3. Following are OOP concepts explained in brief, we’ll take the topics in detail.
1) Data Abstraction: - Data Abstraction is a concept in which the internal and superfluous details
of the implementation of a logic is hidden from an end user(who is using the program) .A user
can use any of the data and method from the class without knowing about how this is created
or what is the complexity behind it. In terms of a real world example, when we drive a bike and
change the gears we don’t have to care about how internally its working, like how liver is pulled
or how chain is set.
2) Inheritance: - Inheritance is most popular Concept in OOP’s .This provides a developer an
advantage called reusability of code. Suppose a class is written having functions with specific
logic, then we can derive that class into our newly created class and we don’t have to write the
logic again for derived class functions, we can use them as it is.
3) Data Encapsulation: - Wrapping up of member data and member functions of a class in a single
unit is called encapsulation. The visibility of the member functions, data members is set via
access modifiers used in class.
4) Polymorphism: - Poly means many and morphism means much function The Concepts
Introduces in the form of many behaviours of an object.
5) Message Communication: - Message Communication means when an object passes the call to
method of class for execution.
OK, we covered lots of theory, now it’s time for action. I hope that will be interesting.
Polymorphism:
In this article we will cover almost all the scenarios of compile type polymorphism, the use of params keyword
in detail, and case study or hands on to different possible combinations of the thoughts coming to our mind
while coding.
Method Overloading or Early Binding or Compile Time Polymorphism:
4. 1. Let’s create a simple console application named InheritanceAndPolymorphism, and add a class named
Overload.cs and add three methods named DisplayOverload having varied parameters as follows,
Overload.cs
public class Overload
{
public void DisplayOverload(int a){
System.Console.WriteLine("DisplayOverload " + a);
}
public void DisplayOverload(string a){
System.Console.WriteLine("DisplayOverload " + a);
}
public void DisplayOverload(string a, int b){
System.Console.WriteLine("DisplayOverload " + a + b);
}
}
In the main method in Program.cs file, add the following code,
Program.cs
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.DisplayOverload(100);
overload.DisplayOverload("method overloading");
overload.DisplayOverload("method overloading", 100);
Console.ReadKey();
}
}
Now when you run the application, output is,
Output:
DisplayOverload 100
DisplayOverload method overloading
DisplayOverload method overloading100
The class Overload contains three methods named DisplayOverload, they only differ in the datatype of the
parameters consist of. In C# we can have methods with the same name, but the datatypes of their parameters
should differ. This feature of C# is called method overloading. Therefore we need not to remember lots of
method names if a method differs in behavior, only providing different parameters to the methods can call a
method individually.
5. Point to remember: C# recognizes the method by its parameters and not by its name.
A signature signifies the full name of the method. So the name of a method or its signature is the original
method name + the number and data types of its individual parameters.
If we run project using following code,
public void DisplayOverload() { }
public int DisplayOverload(){ }
We certainly get a compile time error as,
Error: Type 'InheritanceAndPolymorphism.Overload' already defines a member called 'DisplayOverload'
with the same parameter types
Here we had two functions who differ only in the data type of the value that they return, but we got a compile
time error, therefore another point to remember comes,
Point to remember: The return value/parameter type of a method is never the part of method signature if the
names of the methods are same. So this is not polymorphism.
If we run the project using following code,
static void DisplayOverload(int a) { }
public void DisplayOverload(int a) { }
public void DisplayOverload(string a){ }
We again get a compile time error,
Error: Type 'InheritanceAndPolymorphism.Overload' already defines a member called 'DisplayOverload'
with the same parameter types
Can you differenciate with the modification done in above code,we now have two DisplayOverload methods,
that accept an int (integer). The only difference is that one method is marked static. Here the signature of the
methods will be considered same as modifiers such as static are also not considered to be a part of method
signature.
Point to remember: Modifiers such as static are not considered as part of method signature.
If we run the program as per following code, considering the method signature is different now,
private void DisplayOverload(int a) { }
private void DisplayOverload(out int a)
{
a = 100;
}
6. private void DisplayOverload(ref int a) { }
We again get a compile time error,
Error: Cannot define overloaded method 'DisplayOverload' because it differs from another method only on
ref and out
The signature of a method not only consists of the data type of the parameter but also the type/kind of
parameter such as ref or out etc. Method DisplayOverload takes an int with different access modifiers i.e.
out/ref etc, the signature on each is different.
Point to remember: The signature of a method consists of its name, number and types of its formal
parameters. The return type of a function is not part of the signature. Two methods can not have the same
signature and also non-members cannot have the same name as members.
Role of Params Parameter in Polymorphism:
A method can be called by four different types of parameters.
1. pass by value,
2. Pass by reference,
3. As an output parameter,
4. Using parameter arrays.
As explained earlier the parameter modifier is never the part of method signature. Now let’s focus on
Parameter Arrays.
A method declaration means creating a separate declaration space in memory. So anything created will be lost
at the end of the method.
Running following code,
public void DisplayOverload(int a, string a) { }
public void Display(int a)
{
string a;
}
Results in compile time error,
Error1: The parameter name 'a' is a duplicate
Error2: A local variable named 'a' cannot be declared in this scope because it would give a different meaning
to 'a', which is already used in a 'parent or current' scope to denote something else
Point to remember: Parameter names should be unique. And also we can not have a parameter name and a
declared variable name in the same function as same.
7. In case of pass by value, the value of the variable is passed and in the case of ref and out, the address of the
reference is passed.
When we run the following code,
Overload.cs:
public class Overload
{
private string name = "Akhil";
public void Display()
{
Display2(ref name, ref name);
System.Console.WriteLine(name);
}
private void Display2(ref string x, ref string y)
{
System.Console.WriteLine(name);
x = "Akhil 1";
System.Console.WriteLine(name);
y = "Akhil 2";
System.Console.WriteLine(name);
name = "Akhil 3";
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
We get out put as,
Output:
Akhil
Akhil 1
Akhil 2
8. Akhil3
We are allowed to pass the same ref parameter as many times as we want. In the method Display the string
name has a value of Akhil. Then by changing the string x to Akhil1, we are actually changing the string name to
Akhil1 as name is passed by reference. Variables x and name refer to the same string in memory. Changing
one changes the other. Again changing y also changes name variable as they refer to the same string anyways.
Thus variables x, y and name refer to the same string in memory.
When we run the following code,
Overload.cs:
public class Overload
{
public void Display()
{
DisplayOverload(100, "Akhil", "Mittal", "OOP");
DisplayOverload(200, "Akhil");
DisplayOverload(300);
}
private void DisplayOverload(int a, params string[] parameterArray)
{
foreach (string str in parameterArray)
Console.WriteLine(str + " " + a);
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
We get output,
9. Output:
Akhil 100
Mittal 100
OOP 100
Akhil 200
We will often get into a scenario where we would like to pass n number of parameters to a method.Since C# is
very particular in parameter passing to methods, if we pass an int where a string is expected, it immediately
breaks down. But C# provides a mechanism for passing n number of arguments to a method, we can achieve it
with the help of params keyword.
Point to remember: This params keyword can only be applied to the last argument of the method.So the n
number of parameters can only be at the end.
In the case of method DisplayOverload, the first argument has to be an integer, the rest can be from zero to
an infinite number of strings.
If we add a method like ,
private void DisplayOverload(int a, params string[] parameterArray, int b) { }
We get a compile time error as,
Error: A parameter array must be the last parameter in a formal parameter list
Thus is is proved that params keyword will be the last parameter in a method, this is already stated in the
latest point to remember.
Overload.cs:
public class Overload
{
public void Display()
{
DisplayOverload(100, 200, 300);
DisplayOverload(200, 100);
DisplayOverload(200);
}
private void DisplayOverload(int a, params int[] parameterArray)
{
foreach (var i in parameterArray)
Console.WriteLine(i + " " + a);
}
10. }
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
When we run the code we get,
200 100
300 100
100 200
Therefore,
Point to Remember: C# is very smart to recognize if the penultimate argument and the params have the same
data type.
The first integer is stored in the variable a, the rest are made part of the array parameterArray.
private void DisplayOverload(int a, params string[][] parameterArray) { }
private void DisplayOverload(int a, params string[,] parameterArray) { }
For the above written code, we again get a compile time error and a new point to remember as well,
Error: The parameter array must be a single dimensional array
Point to remember: same as error above.
The data type of the params argument must be a single dimensional array. Therefore [][]
is allowed but not [,]. We also not allowed to combine the params keyword with ref or out.
Overload.cs:
public class Overload
{
public void Display()
{
string[] names = {"Akhil", "Ekta", "Arsh"};
DisplayOverload(3, names);
11. }
private void DisplayOverload(int a, params string[] parameterArray)
{
foreach (var s in parameterArray)
Console.WriteLine(s + " " + a);
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
Output:
Akhil 3
Ekta 3
Arsh 3
We are therefore allowed to pass a string array instead of individual strings as arguments. Here names is a
string array which has been initialized using the short form. Internally when we call the function
DisplayOverload, C# converts the string array into individual strings.
Overload.cs:
public class Overload
{
public void Display()
{
string [] names = {"Akhil","Arsh"};
DisplayOverload(2, names, "Ekta");
}
private void DisplayOverload(int a, params string[] parameterArray)
{
foreach (var str in parameterArray)
Console.WriteLine(str + " " + a);
}
12. }
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
Output:
Error: The best overloaded method match for 'InheritanceAndPolymorphism.Overload.DisplayOverload(int,
params string[])' has some invalid arguments
Error:Argument 2: cannot convert from 'string[]' to 'string'
So, we got two errors.
For the above mentioned code, C# does not permit mix and match. We assumed that the last string “Ekta”
would be added to the array
of strings names or convert names to individual strings and then add the string “Ekta” to it. Quite logical.
Internally before calling the function DisplayOverload,C# accumulates all the individual parameters and
converts them into one big array for the params statement.
Overload.cs:
public class Overload
{
public void Display()
{
int[] numbers = {10, 20, 30};
DisplayOverload(40, numbers);
Console.WriteLine(numbers[1]);
}
private void DisplayOverload(int a, params int[] parameterArray)
13. {
parameterArray[1] = 1000;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
Output: 1000
We see that the output produced is the proof of concept. The member parameterArray[1] of array has an
initial value of 20 and in the method DisplayOverload,we changed it to 1000. So the original value changes,
this shows that the array is given to the method DisplayOverload, Hence proved.
Overload.cs:
public class Overload
{
public void Display()
{
int number = 102;
DisplayOverload(200, 1000, number, 200);
Console.WriteLine(number);
}
private void DisplayOverload(int a, params int[] parameterArray)
{
parameterArray[1] = 3000;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
14. {
Overload overload = new Overload();
overload.Display();
Console.ReadKey();
}
}
Output:
102
In the above mentioned scenario C# creates an array containing 1000 102 and 200. We now change the
second member of array to 3000 which has nothing to do with the variable number. As DisplayOverload has
no knowledge of numebr, so how can DisplayOverload change the value of the int number? Therefore it
remains the same .
Overload.cs:
public class Overload
{
public void Display()
{
DisplayOverload(200);
DisplayOverload(200, 300);
DisplayOverload(200, 300, 500, 600);
}
private void DisplayOverload(int x, int y)
{
Console.WriteLine("The two integers " + x + " " + y);
}
private void DisplayOverload(params int[] parameterArray)
{
Console.WriteLine("parameterArray");
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Overload overload = new Overload();
overload.Display();
15. Console.ReadKey();
}
}
Output:
parameterArray
The two integers 200 300
parameterArray
Now we talk about method overloading. C# is extremely talented though partial. It does not appreciate the
params statement and treats it as a stepchild. When we invoke DisplayOverload only with one integer, C# can
only call the DisplayOverload that takes a params as a parameter as it matches only one int. An array can
contain one member too . The fun is with the DisplayOverload that is called with two ints now. So here we
have a dilemma. C# can call the params DisplayOverload or DisplayOverload with the two ints. As discussed
earlier, C# treats the params as a second class member and therefore chooses the DisplayOverload with two
ints.When there are more than two ints like in the third method call, C# is void of choice but to grudgingly
choose the DisplayOverload with the params. C# opts for the params as a last resort before flagging an error.
Now a bit tricky example,yet important,
Overload.cs:
public class Overload
{
public static void Display(params object[] objectParamArray)
{
foreach (object obj in objectParamArray)
{
Console.Write(obj.GetType().FullName + " ");
}
Console.WriteLine();
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
object[] objArray = { 100, "Akhil", 200.300 };
object obj = objArray;
Overload.Display(objArray);
Overload.Display((object)objArray);
Overload.Display(obj);
16. Overload.Display((object[])obj);
Console.ReadKey();
}
}
Output:
System.Int32 System.String System.Double
System.Object[]
System.Object[]
System.Int32 System.String System.Double
In the first instance we are passing the method Display an array of object that looks like object. Since all the
classes are derived from a common base class object, we can do that. The method Display gets an array of
objects objectParamArray. In the foreach object class has a method named GetType that returns an object
that looks like Type, which too has a method named FullName that returns the name of the type. Since three
different types displayed. In the second method call of Display we are casting objArray to an object.Since there
is no conversion available from converting an object to an object array i.e. object [], so only a one element
object [] is created. It's the same case in the third invocation and the last explicitly casts to an object array.
For proof of concept,
Overload.cs
public class Overload
{
public static void Display(params object[] objectParamArray)
{
Console.WriteLine(objectParamArray.GetType().FullName);
Console.WriteLine(objectParamArray.Length);
Console.WriteLine(objectParamArray[0]);
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
object[] objArray = { 100, "Akhil", 200.300 };
Overload.Display((object)objArray);
Console.ReadKey();
}
}
17. Output:
System.Object[]
1
System.Object[]
Conclusion:
In this article of our Diving in OOP series we learnt about compile time polymorphism, it is also called
early binding or method overloading. We catered most of the scenarios specific to polymorphism.We
also learned about the use of powerful params keyword and its use in polymorphism.
To sum up lets list down all the point to remembers once more,
1. C# recognizes the method by its parameters and not by its name.
2. The return value/parameter type of a method is never the part of method signature if the names of
the methods are same. So this is not polymorphism.
3. Modifiers such as static are not considered as part of method signature.
4. The signature of a method consists of its name, number and types of its formal parameters. The
return type of a function is not part of the signature. Two methods can not have the same signature
and also non-members cannot have the same name as members.
5. Parameter names should be unique. And also we can not have a parameter name and a declared
variable name in the same function as same.
6. In case of pass by value, the value of the variable is passed and in the case of ref and out, the
address of the reference is passed.
7. This params keyword can only be applied to the last argument of the method.So the n number of
parameters can only be at the end.
8. C# is very smart to recognize if the penultimate argument and the params have the same data type.
9. Parameter array must be a single dimensional array.
. Happy Coding.
18. About Author
Akhil Mittal works as a Sr. Analyst in Magic Software and have an experience of more than 8 years in C#.Net. He is a
codeproject and a c-sharpcorner MVP (Most Valuable Professional). Akhil is a B.Tech (Bachelor of Technology) in
Computer Science and holds a diploma in Information Security and Application Development from CDAC. His work
experience includes Development of Enterprise Applications using C#, .Net and Sql Server, Analysis as well as Research
and Development. His expertise is in web application development. He is a MCP (Microsoft Certified Professional) in
Web Applications (MCTS-70-528, MCTS-70-515) and .Net Framework 2.0 (MCTS-70-536).