473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Overloading in c#

Can we use overload keyword in overloading operation in C# ?

In the below example 'overloading is done'.If the same example is used in vb.net,'overload' keyword is used.I want to know can we use 'overload' keyword here and does c# use 'overload' keyword ?

public class class1
{
public void area(int l, int b)
{
int ar;
ar = (l * b);
MessageBox.Show("area of rectangle=" + ar);
}

public void area(int a)
{
int ar;
ar = (a * a);
MessageBox.Show("area of square=" + ar);
}

}

private void button1_Click(object sender, EventArgs e)
{
class1 c1 = new class1();
c1.area(3, 4);
c1.area(4);

}
Aug 24 '07 #1
4 2218
dip_developer
648 Expert 512MB
Can we use overload keyword in overloading operation in C# ?

In the below example 'overloading is done'.If the same example is used in vb.net,'overload' keyword is used.I want to know can we use 'overload' keyword here and does c# use 'overload' keyword ?

public class class1
{
public void area(int l, int b)
{
int ar;
ar = (l * b);
MessageBox.Show("area of rectangle=" + ar);
}

public void area(int a)
{
int ar;
ar = (a * a);
MessageBox.Show("area of square=" + ar);
}

}

private void button1_Click(object sender, EventArgs e)
{
class1 c1 = new class1();
c1.area(3, 4);
c1.area(4);

}
only the difference is there is an extra "s" ...........
The Overloads keyword is used in VB.NET
while the Overload keyword is used in C# (There is no other differences)
Aug 24 '07 #2
Ok.In this example I tried to use 'overload' keyword in 'public void area(int l, int b)'.But when I typed it is showing 'overloading' keyword only.Could you tell me where to use 'overload' keyword in this program ?

Regards...

Manjit Sarma
Aug 27 '07 #3
Plater
7,872 Expert 4TB
In C# (and I had thought in VB.NET, but maybe not)
The normal thought on function overloading is done implicitly without the overload keyword.

void area(int a)
and
void area(int a, int b)

Don't need anything else with them.

In c# the OVERLOAD keyword is used when you wish to overload a function already implemented in a base class. The most commonly overloaded function is the ToString()

If I make my own class, the default .ToString() function will just return the name of my class
Expand|Select|Wrap|Line Numbers
  1. public class myclass
  2. {
  3.    public myclass()
  4.    {//my generic constructor
  5.    }
  6. }
  7.  
But I can overload it with:
Expand|Select|Wrap|Line Numbers
  1. public class myclass
  2. {
  3.    public myclass()
  4.    {//my generic constructor
  5.    }
  6.    public overload string ToString()
  7.    {//my custom .ToString() function
  8.       return "This is my ToString()";
  9.    }
  10. }
  11.  
Aug 27 '07 #4
Thank you very much for clearing my doubt.I will work on 'Overloading' examples now.

Regards...

Manjit Sarma
Aug 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Terje Slettebų | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
15
by: lordkain | last post by:
is it possible to do some kind of function overloading in c? and that the return type is different
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.