473,569 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# to VB.NET IClonable

Hello,

There is a C# funciton I'm trying to translate that clones some event handlers.

public virtual object Clone()
{
...... Instance of a Custom Collection .......
myCol.ItemAdded = this.ItemAdded;
myCol.ItemRemov ed = this.ItemRemove d;
return myCol;
}

In VB.NET I have this.

Public Overridable Function Clone() As Object Implements ICloneable.Clon e
...... Instance of a Custom Collection .......
myCol.ItemAdded = me.ItemAdded
myCol.ItemRemov ed = me.ItemRemoved
return myCol
End Function

The system tells me I need to use a 'RaiseEvent' statement to raise an event.

How do I go about doing the same thing in VB.NET that was done in C#?

Thank You
AM

Jul 21 '05 #1
3 2089
Use this
AddHandler myCol.ItemAdded , AddressOf me.ItemAdded


"AMerrell" <an*******@msne ws.microsoft.co m> wrote in message
news:e7******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

There is a C# funciton I'm trying to translate that clones some event
handlers.

public virtual object Clone()
{
...... Instance of a Custom Collection .......
myCol.ItemAdded = this.ItemAdded;
myCol.ItemRemov ed = this.ItemRemove d;
return myCol;
}

In VB.NET I have this.

Public Overridable Function Clone() As Object Implements ICloneable.Clon e
...... Instance of a Custom Collection .......
myCol.ItemAdded = me.ItemAdded
myCol.ItemRemov ed = me.ItemRemoved
return myCol
End Function

The system tells me I need to use a 'RaiseEvent' statement to raise an
event.

How do I go about doing the same thing in VB.NET that was done in C#?

Thank You
AM


Jul 21 '05 #2
Hi,

AddHandler myCol.ItemAdded , AddressOf Me.ItemAdded gives me 'AdressOf' operand must be the name of a method; no parantheses are needed.
Not sure why it mentions parantheses since the are none.

Thanks,
AM
Jul 21 '05 #3
Because Me.ItemAdded must be a sub or a function.
myCol.ItemAdded must be an event declaration.
Public Class Col

Public Event ItemAdded()

End Class

Public Class Clones

Sub ItemAdded()

End Sub

Function Clone() as Object

....

AddHandler myCol.ItemAdded , me.ItemAdded

return myCol

End Function

End Class

"AMerrell" <an*******@msne ws.microsoft.co m> wrote in message
news:ed******** ******@tk2msftn gp13.phx.gbl...
Hi,

AddHandler myCol.ItemAdded , AddressOf Me.ItemAdded gives me 'AdressOf'
operand must be the name of a method; no parantheses are needed.
Not sure why it mentions parantheses since the are none.

Thanks,
AM


Jul 21 '05 #4

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

Similar topics

5
3652
by: Zürcher See | last post by:
If I want to implement an IClonable interface, how can I copy the events from my source object to the target "cloned" object?
7
3741
by: Tiësto | last post by:
Hi everybody. I know everyone has said to me that this doesn't exist but I'm going to try anyway. I have an instance of ClassA and I want to duplicate that instance, creating another one that is independient of the first one. Isn't there any automatic way to do this? Do I have to write IClonable implementation for each and every class? ...
1
2329
by: oDDskOOL | last post by:
I realized today that the Hashtable.Clone only produces a shallow copy... that makes me go mad that M$ doesn't even provide a deep copy ctor for the Hashtable class ! mighty tech ducks might reply "oh but what if the types in hastable don't have copy ctors defined? that could lead to dangerous situations". well, but was it a significant...
14
2702
by: Arne | last post by:
In C++ we have a copy constructor. What is the equivalent in .Net? Would that be a clone method?
3
475
by: AMerrell | last post by:
Hello, There is a C# funciton I'm trying to translate that clones some event handlers. public virtual object Clone() { ...... Instance of a Custom Collection ....... myCol.ItemAdded = this.ItemAdded; myCol.ItemRemoved = this.ItemRemoved; return myCol;
2
19458
by: Nathan | last post by:
I'm working with Clone() for the first time, and noticed that you have to unbox the Clone of an object that implements ICloneable: MyObject var1 = new MyObject(); // Where MyObject implements ICloneable MyObject va3 = (MyObject)var1.Clone(); Does anyone know why the 2.0 framework doesn't include a Generic implementation of the...
6
1824
by: Larry Minton | last post by:
Is there a C++ method comparable to the vb.net TryCast function? I had hopes for Convert::ChangeType, but that didn't work. For a scripting engine, the user is specifying to retrieve an interface on an object by name. Code is roughly: array<Type^> ^l_pInterfaces = l_pType->GetInterfaces(); for(int m=0; m < l_pInterfaces->Length; m++) {...
2
10096
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx This artivle seems to hint that I should not use System.IClonable but instead define my own interface(s) for cloning. Now since this...
15
2715
by: Gustaf | last post by:
Using VS 2005. I got an 'IpForm' class and an 'IpFormCollection' class, containing IpForm objects. To iterate through IpFrom objects with foreach, the class is implemented as such: public class IpFormCollection : IEnumerable<IpForm> { ArrayList forms = new ArrayList(); public IEnumerator<IpFormGetEnumerator() {
0
7700
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...
0
7614
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...
0
7924
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. ...
0
8125
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...
0
7974
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...
0
5219
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...
1
2114
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
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.