473,405 Members | 2,154 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,405 software developers and data experts.

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 7567
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
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
by: Niklas | last post by:
H What is Java Webstart counterpart in .NET Regard /Niklas
0
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
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
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
by: samadams_2006 | last post by:
In the Java world you create a Servlet that extends the HttpServlet Class, as in: ----------------------------------------------------------------------------------------------------------------...
1
by: sasanka | last post by:
Hi All, What is the counterpart of Application.StartupPath (Windows.Forms) in web forms ? Thanks Sasanka.
2
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.