473,625 Members | 3,353 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 7574
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 myRenamedParame ter) {
// do something
}
void IMyInterface.My Method(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.My Method

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 myRenamedParame ter) {
// do something
}
void IMyInterface.My Method(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 ConsoleApplicat ion1.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
1816
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
2588
by: Niklas | last post by:
H What is Java Webstart counterpart in .NET Regard /Niklas
0
1144
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 in C#??? What is the right way to solve this problem? ;o) Best Regards Thomas
6
30388
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
911
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 entering the procedure? thanks in advance, rodchar
1
2548
by: samadams_2006 | last post by:
In the Java world you create a Servlet that extends the HttpServlet Class, as in: ---------------------------------------------------------------------------------------------------------------- public class ExampServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...
1
14229
by: sasanka | last post by:
Hi All, What is the counterpart of Application.StartupPath (Windows.Forms) in web forms ? Thanks Sasanka.
2
6783
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 take the first specified amount of signs in a text-column and print them out. For example: Instead of printing out all information in a text-column... SELECT story FROM table01; Once upon a time in a land far far away lorem ipsum dolor sit amet,...
4
7187
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 and decode using decodeURI(). But still there are unsolved characters and some +, %, and hex numbers. What is exact dotnet counterpart of JS decodeURI()? I am not sure this matters. I am not using typical asp.net + JS. I am using...
0
8256
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
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 we have to send another system

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.