473,499 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# counterpart to VB.NET Implements

Hi
I have an Interface with some methods but I dont want the class which
implements this Interface to have the same method name as the interface
method names. In VB.NET I can use implement but have do I do it i C#?
Regards
/Niklas
Feb 10 '06 #1
6 7568
If I understand the question correctly, implement the interface explicitely:

public interface IMyInterface {
void MyMethod(int myParameter);
}
public class MyClass : IMyInterface {
public void MyRenamedMethod(int myRenamedParameter) {
// do something
}
void IMyInterface.MyMethod(int myParameter) {
MyRenamedMethod(myParameter);
}
}

Note that you don't actually need to expose it on the *default* interface at
all...

Marc
Feb 10 '06 #2
I want to do something like this:

public interface IMyInterface {
void MyMethod(int myParameter);
}

public class MyClass : IMyInterface {
void MyNewMethodName(int myParameter) implements MyMethod
{
//Do something
}
}

I want the compiler to accept that I have another name for
IMyInterface.MyMethod

Regards
/Niklas

"Marc Gravell" wrote:
If I understand the question correctly, implement the interface explicitely:

public interface IMyInterface {
void MyMethod(int myParameter);
}
public class MyClass : IMyInterface {
public void MyRenamedMethod(int myRenamedParameter) {
// do something
}
void IMyInterface.MyMethod(int myParameter) {
MyRenamedMethod(myParameter);
}
}

Note that you don't actually need to expose it on the *default* interface at
all...

Marc

Feb 10 '06 #3
C# does not offer this. In fact, IIRC the framework doesn't either (due to
reflection); I suspect that VB simply does something like my code
behind-the-scenes; you could run your VB assembly through Roeder's Reflector
and see what it compiled to?

(http://www.aisto.com/roeder/dotnet/)

Marc
Feb 10 '06 #4
No, VB doesn't do anything behind-the-scenes. CLR supports that.

Feb 10 '06 #5
I stand corrected, then (I did say IIRC...); I have checked in reflector,
and you are correct - it is provided in the IL in a way closer to the VB
than the C#:

.method public newslot virtual final instance void RenamedTest() cil
managed
{
.override ConsoleApplication1.Interface1::Test
}

However, I think the short of it is that you still can't (unless I am wrong
again) do this in C#.

Marc
Feb 10 '06 #6
There is no way to replace the name, but you can offer two methods, the one
with the changed name calling the interface method.

There's a good reason you shouldn't be able to use a different name for the
interface implementing method (even though VB allows it). It's confusing to
someone using your class if the methods they expect to see, which implement
the documented interface, aren't there.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Niklas" wrote:
Hi
I have an Interface with some methods but I dont want the class which
implements this Interface to have the same method name as the interface
method names. In VB.NET I can use implement but have do I do it i C#?
Regards
/Niklas

Feb 10 '06 #7

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

Similar topics

1
1805
by: Jinming Xu | last post by:
Hi Folks, Could any of you please teach me what's the counterpart of Python None in C++ side? Since I need to manipulate a Python None in C++. Thanks a lot, Jinming Xu ...
1
2565
by: Niklas | last post by:
H What is Java Webstart counterpart in .NET Regard /Niklas
0
1136
by: Thomas | last post by:
Hello everybody, I have a C++ application which gives a DLL 2 handles from cevent objects. Now I need to use this DLL with C#, but I don't know how to create a counterpart of the cevent object...
6
30348
by: Andrew | last post by:
Hi, friends, In VB, there is a vbCrLf for a new line. What is the counterpart in C#? Thanks.
0
899
by: rodchar | last post by:
Hey all, I was wondering if there is a repaint counterpart in asp.net. I have a literal that i want to show before going into a procedure but it's not working. How do I refresh the screen before...
1
2536
by: samadams_2006 | last post by:
In the Java world you create a Servlet that extends the HttpServlet Class, as in: ----------------------------------------------------------------------------------------------------------------...
1
14219
by: sasanka | last post by:
Hi All, What is the counterpart of Application.StartupPath (Windows.Forms) in web forms ? Thanks Sasanka.
2
6764
Paks
by: Paks | last post by:
Hello, I have a quick little question about the MySQL-command LEFT(columnName,int). My question is if there's a counterpart in PostgreSQL for this command and what it is? What I want to do is...
4
7177
by: Han | last post by:
Hello I am passing string from dotnet to javascript. ", ', newline characters, and something. So I am using httputility.urlEncode() to make it neat. Now a JS function accepts the encoded string...
0
7007
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...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
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
5468
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,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.