473,396 Members | 1,804 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,396 software developers and data experts.

Can this method overload be resolved?

Given the following code
Is there any way to call one of the Bar methods.

using System;

class Program
{
static void Main()
{
Foo<string, stringfoo = new Foo<string,string>();
string s = "";

foo.Bar(s); // Compiler error CS0121

}
}

class Foo<T, S>
{
public void Bar(T a)
{
Console.WriteLine("Bar(T)");
}

public void Bar(S a)
{
Console.WriteLine("Bar(S)");
}
}
Nov 28 '06 #1
3 1508
Christof Nordiek wrote:
| Given the following code
| Is there any way to call one of the Bar methods.

I don't think there is, unless T and S are different types (e.g. Foo<string,
boolfoo = new Foo<string,bool>();)

--
Christopher Ireland

"I am always doing that which I can not do, in order that I may learn how to
do it."
Pablo Picasso
Nov 28 '06 #2
You're passing the type parameter to the Console.WriteLine method. pass the
method parameter instead.

--
HTH,

Kevin Spencer
Microsoft MVP
Virtual Carpenter
http://unclechutney.blogspot.com

Paranoia is a state of mind.
"Christof Nordiek" <cn@nospam.dewrote in message
news:ul**************@TK2MSFTNGP06.phx.gbl...
Given the following code
Is there any way to call one of the Bar methods.

using System;

class Program
{
static void Main()
{
Foo<string, stringfoo = new Foo<string,string>();
string s = "";

foo.Bar(s); // Compiler error CS0121

}
}

class Foo<T, S>
{
public void Bar(T a)
{
Console.WriteLine("Bar(T)");
}

public void Bar(S a)
{
Console.WriteLine("Bar(S)");
}
}

Nov 28 '06 #3
Christof Nordiek wrote:
Given the following code
Is there any way to call one of the Bar methods.

using System;

class Program
{
static void Main()
{
Foo<string, stringfoo = new Foo<string,string>();
string s = "";

foo.Bar(s); // Compiler error CS0121

}
}

class Foo<T, S>
{
public void Bar(T a)
{
Console.WriteLine("Bar(T)");
}

public void Bar(S a)
{
Console.WriteLine("Bar(S)");
}
}
Per the spec, it cannot be resolved and should properly fail. See this
example in the spec:

class G2<U,V>
{
void F3(U u, V v); // Valid, but overload resolution
for
void F3(V v, U u); // G2<int,int>.F3 will fail

void F4(U u, I1<Vv); // Valid, but overload resolution for
void F4(I1<Vv, U u); // G2<I1<int>,int>.F4 will fail

void F5(U u1, I1<Vv2); // Valid overload
void F5(V v1, U u2);

void F6(ref U u); // valid overload
void F6(out V v);
}
--
Tom Porterfield

Nov 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Clinton Pierce | last post by:
I can create a delegate like this, and everything works fine: class Foo { private delegate void NextPanel(); private NextPanel myself; // And later in a method private void EffStart() {
19
by: Dave Raskin | last post by:
public class Base { } public class Derived : Base { } public class Service {
4
by: Lenn | last post by:
I have the following method: public void Execute(TCPCommand command, out string outputResponse, out string error) { //snipped code outputResponse = "some message"; error = ""; }
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
10
by: Mihai Osian | last post by:
Hi everyone, Given the code below, can anyone tell me: a) Is this normal behaviour ? b) If it is, what is the reason behind it ? I would expect the A::method(int) to be inherited by B. ...
11
by: Gary James | last post by:
I'm using an object data type variable to pass a numeric value (Int, Float, Double, etc) to a function that returns a formatted string. However, nullable types do not provide an overridden...
5
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar...
3
by: Mucahit ikiz | last post by:
Can you help me please, I have this error message "No overload for method 'GetDataByClassType'takes '1' arguments" private void button7_Click(object sender, EventArgs e) { string...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.