473,806 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Equivalent of VB.NET MyClass???

In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden
methods in derived classes?
Nov 15 '05 #1
8 3269
I believe the keyword you seek is "this".
If you are in a class and type "this." (this and a period)
you should see the methods/ members in that class.
If you wish to refer to a method in a derived class,
use the "base" keyword.

Does that help?
Peter
"FDude" <fd***@hotmail. com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden
methods in derived classes?

Nov 15 '05 #2
"Peter Bromberg [C# MVP]" <pb*******@yaho o.com> wrote in message news:#5******** ******@TK2MSFTN GP10.phx.gbl...
I believe the keyword you seek is "this".


this in C# == me is VB. I think base is MyBase is vb. I think MyClass can be used by a base class to find what has inherited it. I
don't think C# has this.

--
Michael Culley
Nov 15 '05 #3
FDude wrote:
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially
overriden methods in derived classes?


Decorate your methods with the virtual keyword and the proper method will be
called every time assuming it's implemented in the current type.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
There is no equivalent to MyClass in C#.

Me = this
MyBase = base
MyClass has no equivalent

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"FDude" <fd***@hotmail. com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden
methods in derived classes?

Nov 15 '05 #5
Hey Peter,

The VB equivalent to "this" is "Me". It works exactly the same way.

On the other hand, MyClass says to always call this classes implementation
of a method or property even if it is overriden by a derived class.

Class Foo
Public Overridable Function Bar(ByVal x as Integer) As Integer
Return x + x
End Function

Public Sub Test()
MsgBox(Me.Bar(1 0))
MsgBox(MyClass. Bar(10))
End Sub
End Class

Class Foo2 : Inherits Foo
Public Overrides Function Bar(ByVal x as Integer) As Integer
Return x * x
End Function
End Class

Sub Main()
Dim f2 as New Foo2()
f2.Test()
' First MsgBox shows 100 - Foo2's implementation of Bar
' Second MsgBox shows 20 - Foo's implementation of Bar
End Sub

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Peter Bromberg [C# MVP]" <pb*******@yaho o.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I believe the keyword you seek is "this".
If you are in a class and type "this." (this and a period)
you should see the methods/ members in that class.
If you wish to refer to a method in a derived class,
use the "base" keyword.

Does that help?
Peter
"FDude" <fd***@hotmail. com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden
methods in derived classes?


Nov 15 '05 #6
So how do you ensure you are always calling the same function even if it is overriddden? I guess you could create a private function
and call that, but maybe there is an easier way.

--
Michael Culley
"Rob Windsor [MVP]" <rw******@NO.MO RE.SPAM.bigfoot .com> wrote in message news:eT******** ******@TK2MSFTN GP10.phx.gbl...
There is no equivalent to MyClass in C#.

Me = this
MyBase = base
MyClass has no equivalent

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"FDude" <fd***@hotmail. com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden
methods in derived classes?


Nov 15 '05 #7

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:u7******** ******@TK2MSFTN GP10.phx.gbl...
So how do you ensure you are always calling the same function even if it is overriddden? I guess you could create a private function and call that, but maybe there is an easier way. Usually you don't worry about it, you should design in such a way that you
don't need to, however a private method is more or less your only option if
you *have* to call your local method.
Can I ask why you need to use a local method without virtuality?
--
Michael Culley
"Rob Windsor [MVP]" <rw******@NO.MO RE.SPAM.bigfoot .com> wrote in message

news:eT******** ******@TK2MSFTN GP10.phx.gbl...
There is no equivalent to MyClass in C#.

Me = this
MyBase = base
MyClass has no equivalent

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"FDude" <fd***@hotmail. com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
In otherwords, how do I force a method in my class to call the method
implementations in the SAME class and not use any potentially overriden methods in derived classes?



Nov 15 '05 #8
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
Can I ask why you need to use a local method without virtuality?


I don't, the OP does.

--
Michael Culley
Nov 15 '05 #9

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

Similar topics

11
2576
by: modemer | last post by:
If I define the following codes: void f(const MyClass & in) {cout << "f(const)\n";} void f(MyClass in) {cout<<"f()\n";} MyClass myclass; f(myclass); Compiler complain that it can't find the best match. Anyone could give a detail explanation in theory? Which one is good?
9
2070
by: Krishnan | last post by:
Hi, Just curious to know if there's a keyword equivalent to "Myclass" in VB.Net in C# TIA Krishnan
8
2178
by: Mark Rae | last post by:
Hi, Another stupid newbie question from me, I'm sorry to say... but can anyone tell me how to simulate the concept of a global constant in a C# Windows app? The app in question contains several forms, each of which need to interrogate the value of a "global" constant. Do I have to create a class with a public constant declaration and instantiate that class from each form?
6
33123
by: John Grandy | last post by:
Does C# have an equivalent for VB.NET's Redim Preserve ? ReDim Preserve increases the final dimension of any array while preserving the array's contents (however, the type of the array may not be changed).
24
3589
by: Water Cooler v2 | last post by:
What is the difference between the Me and the MyClass keywords? I understand Me that it represents the specific instance of the class. When you're inside the object instance, it refers to itself using the Me keyword. What is the MyClass keyword used for?
21
49057
by: clintonG | last post by:
Will somebody convert this for me... System.Web.UI.HtmlControls.HtmlHead header; header = TryCast(this.Page.Header, System.Web.UI.HtmlControls.HtmlHead); <%= Clinton Gallagher NET csgallagher AT metromilwaukee.com URL http://clintongallagher.metromilwaukee.com/ MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
2
2813
by: Maksim Kasimov | last post by:
Hi, in any python class it is possible to define __getattr__ method so that if we try to get some value of not actually exists instance attribute, we can get some default value. For example: class MyClass: def __getattr__(self, attname):
5
8740
by: pelon | last post by:
Hey! I'm new to OO in PHP but somewhat familiar with this paridigm in JAVA.... So I was wondering if it is possible to have within a PHP script something equivalent to a main method as it is possible in JAVA.... For example:
0
9597
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
10620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
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,...
1
7650
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
6877
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
5546
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...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.