Overloading Assignment Operator?

Jan 9, 2010

i would like to hijack the assignment operator and do some customization before an instance of my class is assigned.

example:
Dim A as New MyClass
Dim B as MyClass = A

i want custom the behavior of = is that possible?

View 9 Replies


ADVERTISEMENT

Consider Operator Overloading In .net?

Sep 9, 2009

What scenarios would you consider operator overloading in .net?

View 5 Replies

Operator Overloading In Getting Some Kind Of Compatibility?

Jul 15, 2010

I'm working together with someone on a project, but I'm writing code in VB.Net, and hes coding in VC++. I'm trying to get some kind of compatability going on, so I'm putting my support classes into a VB dll. I've tested it a little, and it seems that all of the functions work, but the operator overloading that I did in VB doesnt seem to carry over to C++.

View 2 Replies

Something Like Operator Overloading For Only Part Of An Objects Properties?

Aug 21, 2009

For good reasons I would like to have something like truckA = truckB + truckC where only the loads of the trucks are added, not the license plate numbers. Also I don't really want to return a new object (lots of overhead), just change one or two of the properties. Only thing I can come up with is truckA.Load = truckB.Load + truckC.Load, or at best truckA.Load = truckB + truckC which still doesn't look elegant, and - worse - still requires the creation of a new Load object.(this is just a way of stating my problem; the real objects are quite big and complicated) Currently I have a Sub isSumOf so the code reads TruckA.isSumOf(truckB, TruckC)

View 4 Replies

Define An Assignment Operator In Structure?

Jul 9, 2010

I am having a structure that is actually a simple byte with more functionality.[code]...

If there would be a way to inherit from Structure I would simply inherit from Byte adding my functionality, basically I just need a byte Structure with custom functionality.

My question is also valid when you want to define your new singleton member value-types (like, you want to define a nibble-type for instance etc.) and you want to be able to set it with an assignment to number or other language typed representation.

View 1 Replies

3.5 Assignment Operator Assigning Pointer Instead Of Copying?

Dec 16, 2010

My program has decided to assign pointers instead of make copies of an object, and I'm not sure why. I have something like this:

Public Class Foo
Private myFooData As New List(Of FooData)
Public Sub New(ByVal newFooData As List(Of FooData))

[Code]....

Very simplified, but basically what I'm doing. So for some reason today when I change item in newFoo.FooValues, originalFoo.FooValues also changes, and mainFoo does not. I've tried assigning the entire objects as well and I get the same results.

View 2 Replies

Lamdba Expression, Use Assignment Operator Instead Of Equality?

Oct 27, 2010

I have a method that takes an System.Action, this is what I'm trying to feed it:Function() Me._existingImports = Me.GetImportedAds()

The thing is that it complains about the = sign since it thinks I'm trying to do a comparison, which I'm not. I want to assign the Me._existingImports the value of Me.GetImportedAds(), but VB.NET complains about DataTable not having a = operator.

How can I force it to use the assignment operator instead of the equality operator?

In C# this works perfectly fine: () => this.existingImports = this.GetImportedAds()

For now the solution will be to use a standalone method, but that's way more code than needed.

View 1 Replies

Does The Assignment Operator In 1.1 Do A Member-by-member Copy Of The ObjOriginal To ObjClone

Nov 18, 2009

I'm "cloning" objects in my code. For instance: objClone = objOriginal My question is: Does the assignment operator in VB.NET 1.1 do a member-by-member copy of the objOriginal to objClone or does objClone simply point as a reference to memory referenced by objOriginal?

View 3 Replies

Error: Option Strict On Disallows Operands Of Type Object For Operator '='. Use The 'Is' Operator To Test For Object Identity

Jan 27, 2010

I am tightening up my coding with the Option Strict set to ON. It has now produced alot of errors. An example of this is:

If AllocatedDGV.Rows(i).Cells("RoomNumber").Value = RoomsAvailableDGV.Rows(j).Cells("RoomName").Value Then

It gives me the following error: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

View 6 Replies

Get An Error Overloading Sub New()

Nov 20, 2009

I have a module with code that refers to controls on form1 form1.textbox1.text 'after adding the sub new overload below to my form my module gives me "reference to a non shared member requires an object reference" why is that? [code]

View 9 Replies

Get An Error Overloading Sub New()?

Jul 28, 2011

passing a variable to another formI have a module with code that refers to controls on form1form1.textbox1.text 'after adding the sub new overload below to my form my module gives me "reference to a non shared member requires an object reference"

View 2 Replies

Option Strict On Disallows Operands Of Type Object For Operator Use The 'Is' Operator To Test For Object Identity

Apr 6, 2012

I need to write an interface to get data to/from our data files.

We have a low level class that holds field values for each record read from the files.

This just holds two values, the value read from the file (DBValue) and the updated value that may need to be written back to the file (CurrentValue).

These values may be any of the standard value types (integer, date etc) or a string.

Either value (DBValue or CurrentValue) may be null if not defined.

I have written the class to manage this data which works fine while option strict is NOT on.

But we have an office policy of having option strict on all the time.

When I put option strict on, my object value comparisons fail with the error: "Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity."

Question, how should I change the following code to handle option strict on ...

This is all running on Visual Studio 2010

[Code]...

View 1 Replies

Coalesce Operator And Conditional Operator In .NET?

Mar 10, 2009

Possible Duplicate: Is there a conditional ternary operator in VB.NET?

Can we use Coalesce operator(??) and conditional ternary operator(:) in VB.NET as in C#?

View 5 Replies

Asp.net - Overloading Enums And Properties In .NET?

Sep 23, 2010

I have a base class with the the following enum and property:

[Code]...

First off, how do I do this - is it by simply overloading it? And secondly will my original property pick up the new enum automatically when using the derived class or will I need to overload that too?

View 2 Replies

Overloading A Property's Set Method?

May 12, 2012

maybe it's not a method exactly. here's what I'd like to do:

Private _Columns As ArrayList
Public Property Columns() As ArrayList
Get[code]....

which would allow me to conveniently set the property by assigning to it various kinds of collection types... except, I can't do it because apparently the Set method has to take an argument of the type of the property itself... I get the complaint:

'Set' parameter must have the same type as the containing property

is there a way to do this?

View 2 Replies

VS 2005 OverLoading Showdialog?

Sep 28, 2011

I wanna overload the ShowDilog for my form. I wanted to clarify whether the Owner should be passed as Value or Reference.

View 2 Replies

.net - Method Overloading Getting Wrong Overload?

May 3, 2012

I am having a problem convincing Visual Studio and the compiler to use the correct method overload, possibly because of inheritance.

Given these objects:

Public Class Matrix
...
End Class

[code]....

View 2 Replies

.net - Overloading Operators In C++, Exporting And Importing Then In .NET?

Jan 26, 2010

I have a weird situation. I have a C++ code that overloads the +,-,* operators and exports them in a .DLL file. Now, I want to import those overloaded operators from within VB.NET code. So it should be like this:

<DllImport("StructDLL.dll")> Public Shared Function
Operator +(ByVal a1 As A, ByVal a2 As A) As A
End Function

So what I'm trying to do above it just import the lovely overloaded operator + from the DLL.Note that the operator is already overloaded from inside the DLL, so should I import it as a Function or as an Operator like this?

<DllImport("StructDLL.dll")> Public Shared
Operator +(ByVal a1 As A, ByVal a2 As A) As A
End Operator

The overloaded plus operator is supposed to add structs. So the DLL is programmed to work on structs (C++) and I want to import it in VB.NET to work on Structures.

View 1 Replies

Need A Solution To Do Type Parameter Overloading

May 20, 2011

I need type parameter overloading as such:[code..]

so that i can New Map(Of Human) and the compiler will automatically match it to Public Class Map(Of TKey, TValue) and if i new Map(Of String) the compiler will automatically match it to Public Class Map(Of TKey As IEquatable(Of TKey), TValue) (since String is an IEquatable(Of String))

Right now my solution is to give the class different names as such:[code...]

View 2 Replies

Overloading Several Functions In Interface File

Nov 12, 2008

I'm trying to overload several functions. These are first defined in an interface:

Code:
Namespace Scripting
Public Interface IGlobalFunctions
Overloads Function InOutBox(ByVal messageBoxText As String) As DialogResult
Overloads Function InOutBox(ByVal messageBoxText As String, ByVal caption As String) As DialogResult
[Code] .....

It complies and runs.. But I can only use the first version of InOutBox when I try to use the next one I get an error telling me: "Wrong number of arguments or invalid property assignment".

View 1 Replies

VS 2010 Overloading A Method With Different Outputs?

Aug 2, 2010

i recently discovered a nice feature called overloading, now the question is can i also do that for outputs? for example i want to call a function that would automatically return the datatype i assign the function toright now im geting an error saying "blabla and blabla cant overload eachother because they only differ by return types

View 3 Replies

VS 2010 Overloading Operators For Interfaces

Sep 14, 2011

I have a class that implements an interface. Other objects will get an instance via a method like:

Dim AU1 as IAUC = GetAU(<some GUID>)
Dim AU2 as IAUC = GetAU(<some other GUID>)

What I would like to be able to do is this:If AU1 = AU2..The parts of the class that make up the interface could be equal when the rest of the class is not, and the equality of the interface objects (if you can call them that) is complicated. Several fields have to be compared in odd ways.One option I have is to just add an Equality method to the interface, which would work, but I would rather overload the = and <> operators. As far as I can see, you cannot overload operators as part of an interface, but I was hoping that I had overlooked something.

View 2 Replies

C# - Generic Method Overloading Compilation Error In VB?

Aug 5, 2009

I have a problem with the VB.NET compiler failing to compile a class (in a separate C# assembly) which contains two overloads of a method with generic arguments. The equivalent code in C# compiles against the same assembly with no errors. Here are the two method signatures:

protected void SetValue<T>(T newValue, ref T oldValue)
protected void SetValue<T>(T? newValue, ref T? oldValue) where T : struct

Here is the code to three assemblies that demonstrate the problem. The first is the C# assembly with a Base class that implements the generic methods. The second is a C# class derived from Base and calls both overloads of SetValue correctly. The third is a VB class also derived from Base, but fails to compile with the following error message:

[Code]...

Am I doing something wrong in the VB code, or are C# & VB different when it comes to generic overload resolution? If I make the method arguments in Base non-generic then everything compiles correctly, but then I have to implement SetValue for every type that I wish to support.

View 2 Replies

Duplicate Code And Method Overloading / Overriding

May 18, 2012

This is a general question about Object Orientation and specifically overloading functions in .NET (or any other framework or language). I am looking at an application that has a lot of duplicate code. For example, have a look at the following functions: [code] I would of thought that best pratice would be to put: //code that is specifically relevant to Test1 variable in a separate function as it is common in both functions.

View 2 Replies

Function Overloading Add Result Type To Parameter Signature?

Dec 7, 2009

Can someone on the VB language team explain why a function result type is not part of the parameter signature?If it were then function overloads would also work for functions that only differ by the result type. In some cases, this is useful (aka cleaner code) especially when you have strongly typed data.

Other languages have this and implement it by considering the function result as an OUT parameter either as param 0 or at the end of the param list (stack) so existing type matching verification can be performed by the compiler.

In VB, the workaround is just messy and would be easily fixed by a language change. This example is overly simplified and not meant as a solid justification for the request Say you have a parse requiirement that takes a comma delimited string in the form: "31,32,33,34" or "bob,carol,ted,alice"
In you code,

[Code]...

View 1 Replies

Overloading Functions - Overloads In The Abstract Class Implementation ?

Oct 7, 2011

I have recently come across some code that has the following. First there is a Interface with the following function Function Validate() As Boolean. That interface is then implemented in the an 'ABSTRACT' class like this.
Public MustOverride Overloads Function Validate() As Boolean Implements IBusinessEntity.Validate

Question 1: Why use Overloads in the Abstract class implementation.

Question 2: The Abstract class is then inherited into a class (TestClass). In TestClass the Validate function is implemented as follows Public Overloads Overrides Function Validate() As Boolean. I understand the Overrides keyword is to insure that this is the version of the Validate that you want called and not the Abstract class version but why again use the keyword Overloads?

From what I understand you can overload a constructor of a class by simply changing the constructor signature. Also, you overload Methods and Properties of a class by using the Keyword Overloads. But why do it when your implementing an Interface method, or an Abstract Class method that's inherited.

View 2 Replies

How To Use Operator As A Comparison Operator

Nov 11, 2009

I want to perform equality comparison in VB.NET and cannot get it to work. Error: value of type Boolean can not be converted to System.Drawing.PointF

[code]...

View 4 Replies

VB 2010 With The Assignment?

Sep 24, 2011

I have a school assignment and I just started to learn VB. Until now I/ve done pretty good however I encountered a problem which I can't solve in this assignment. So, I would ask if someone could tell me what I'm doing wrong?

This is the assignment:The application calculates the new hourly pay for each of three job codes, given the current hourly pay for each job code and the raise percentage (entered as a decimal number).

a.) before the form appears, use the InputBox function to prompt the personnel clerk to enter the raise percentage. You will use the raise percentage to calculate the new hourly pay for each job code.

[Code]...

View 4 Replies

Why Does The Assignment Fail

Jun 5, 2012

Concerning this code... Dim i1 As Integer = Nothing

[Code]...

View 12 Replies

.net - Perform An Assignment In An IF Conditional In .NET?

Mar 19, 2012

Is there a way to set a variable in VB.NET in an IF statement. I would like to do the following:

[Code]...

Is there some way I can get the last "ElseIf" to work? I know I can re-write it to get it to work but is there some syntax that will make it work the way it is?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved