tagged [operator-overloading]

Define new operators in C#?

Define new operators in C#? > [Is it possible to create a new operator in c#?](https://stackoverflow.com/questions/1040114/is-it-possible-to-create-a-new-operator-in-c) I love C#, but one thing I wi...

23 May at 12:8

C# Generic Operators

C# Generic Operators I am trying to implement a generic operator like so: Really what I'm trying to do is gracefully handle inheritance. With a standard operator + in Foo, where T is instead "Foo", if...

6 May at 00:23

explicit conversion operator error when converting generic lists

explicit conversion operator error when converting generic lists I am creating an explicit conversion operator to convert between a generic list of entity types to a generic list of model types. Does ...

28 Dec at 22:40

How can a C# class be written to test against 0 as well as null

How can a C# class be written to test against 0 as well as null I have a custom class written in C# (2005), with code similar to the following: ``` public class Savepoint { public int iOffset; ...

operator overloading with generics

operator overloading with generics > [Arithmetic operator overloading for a generic class in C#](https://stackoverflow.com/questions/756954/arithmetic-operator-overloading-for-a-generic-class-in-c-sh...

23 May at 11:54

overloading delete, pure virtual func call

overloading delete, pure virtual func call So i want to overload delete of a abstract virtual class. This will call deleteMe() in the derived class which is in another lib. This is to prevent error/cr...

23 May at 12:30

Arithmetic operator overloading for a generic class in C#

Arithmetic operator overloading for a generic class in C# Given a generic class definition like How can I define arithmetic operators for it? The following do

Overloading function call operator in C#

Overloading function call operator in C# Is it possible to overload the default function operator (the () operator) in C#? If so - how? If not, is there a workaround to create a similar affect? EDIT: ...

6 Apr at 12:28

Operator Overloading with C# Extension Methods

Operator Overloading with C# Extension Methods I'm attempting to use extension methods to add an operater overload to the C# `StringBuilder` class. Specifically, given `StringBuilder` `sb`, I'd like `...

Overloading assignment operator in C#

Overloading assignment operator in C# I know the `=` operator can't be overloaded, but there must be a way to do what I want here: I'm just creating classes to represent quantitative units, since I'm ...

27 Dec at 09:44

How do I overload an operator for an enumeration in C#?

How do I overload an operator for an enumeration in C#? I have an enumerated type that I would like to define the `>`, `=`, and `

Is it possible define an extension operator method?

Is it possible define an extension operator method? is it possible to define an extension method that at the same time is an operator? I want for a fixed class add the possibility to use a known opera...

C# GetHashCode/Equals override not called

C# GetHashCode/Equals override not called I'm facing a problem with GetHashCode and Equals which I have overridden for a class. I am using the operator == to verify if both are equal and I'd expect th...

6 Nov at 22:42

Null checking is ambiguous for a class with several overrides for == operator

Null checking is ambiguous for a class with several overrides for == operator I have a class with two overrides for == operator, to compare it to other instances of this class, and to compare to insta...

How do I overload the square-bracket operator in C#?

How do I overload the square-bracket operator in C#? DataGridView, for example, lets you do this: but for the life of me I can't find the documentation on the index/square-bracket operator. What do th...

Operator overloading ==, !=, Equals

Operator overloading ==, !=, Equals I've already gone through [question](https://stackoverflow.com/questions/10790370/whats-wrong-with-defining-operator-but-not-defining-equals-or-gethashcode) I under...

Overloading operator== versus Equals()

Overloading operator== versus Equals() I'm working on a C# project on which, until now, I've used immutable objects and factories to ensure that objects of type `Foo` can always be compared for equali...

25 Sep at 20:17

overload == (and != , of course) operator, can I bypass == to determine whether the object is null

overload == (and != , of course) operator, can I bypass == to determine whether the object is null when I try to overload operator == and != in C#, and override Equal as recommended, I found I have no...

9 Jun at 12:59

How does operator overloading of true and false work?

How does operator overloading of true and false work? You can overload operator true and false i looked at examples and found this [http://msdn.microsoft.com/en-us/library/aa691312%28v=vs.71%29.aspx](...

5 Mar at 10:5

Post-increment Operator Overloading

Post-increment Operator Overloading I'm having problems trying to overload the post increment operator in C#. Using integers we get the following results. But, when I try it using classes, i

3 Apr at 16:57

Operator Overloading and Linq Sum in C#

Operator Overloading and Linq Sum in C# I have a custom type (`Money`) that has an implict conversion to decimal and an overloaded operator for `+`. When I have a list of these types and call the linq...

When should I define a (explicit or implicit) conversion operator in C#?

When should I define a (explicit or implicit) conversion operator in C#? A somewhat little-known feature of C# is the possibility to create implicit or explicit [user-defined type conversions](http://...

C#, multiple == operator overloads without ambiguous null check

C#, multiple == operator overloads without ambiguous null check : I have a few classes which do the same work, but with different value types (e.g. Vectors of floats or integers). Now I want to be abl...

21 Feb at 10:55

Can/should I use implicit operator instead of overriding ToString?

Can/should I use implicit operator instead of overriding ToString? I have a class that I want to easily write out to strings (e.g. for logging purposes). Can I use the implicit operator to implicitly ...