tagged [operators]

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...

How EXACTLY can += and -= operators be interpreted?

How EXACTLY can += and -= operators be interpreted? What exactly (under the hood) do the `+=` and `-=` operators do? Or are they implicit in that they are defined per type? I've used them extensively,...

10 Nov at 06:1

Why are Postfix ++/-- categorized as primary Operators in C#?

Why are Postfix ++/-- categorized as primary Operators in C#? Currently I'm teaching a class of C++ programmers the basics of the C# language. As we discussed the topic operators I used C# standard ca...

Execution order of conditions in C# If statement

Execution order of conditions in C# If statement There are two if statements below that have multiple conditions using logical operators. Logically both are same but the order of check differs. The fi...

Does && in c++ behave the same as && in Java?

Does && in c++ behave the same as && in Java? my question is essentially in the title. Basically I've learned that in Java the && operator acts like a short circuit, so that if the first condition eva...

5 Oct at 16:43

&&= and ||= operators

&&= and ||= operators > [Why doesn't Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=)](https://stackoverflow.com/questions/2324549/why-doesnt-jav...

23 May at 12:9

Why does the compiler evaluate remainder MinValue % -1 different than runtime?

Why does the compiler evaluate remainder MinValue % -1 different than runtime? I think this looks like a bug in the C# compiler. Consider this code (inside a method): It compiles with no errors (or wa...

What do these operators mean (** , ^ , %, //)?

What do these operators mean (** , ^ , %, //)? Other than the standard `+`, `-`, `*`and `/` operators; but what does these mean (`**` , `^` , `%`, `//`) ? ``` >>> 9+float(2) # addition 11.0 >>> 9-floa...

17 Mar at 19:25

Compiler replaces explicit cast to my own type with explicit cast to .NET type?

Compiler replaces explicit cast to my own type with explicit cast to .NET type? I have the following code: This code compi

C# LINQ Orderby - How does true/false affect orderby?

C# LINQ Orderby - How does true/false affect orderby? I was studying a bit of LINQ ordering as I have a list of Ids, and I need to order them sequentially. However, there are certain ids that need to ...

2 Feb at 14:40

Implicit (bool) and == operator override - handle if statements correctly

Implicit (bool) and == operator override - handle if statements correctly I have a custom class with implement both the `==` and the `implicit` for boolean operator. Is this the correct way to handle ...

31 Jan at 16:55

How do I perform explicit operation casting from reflection?

How do I perform explicit operation casting from reflection? I want to use reflection and do either an implicit or explicit coversion using reflection. Given I have defined Foo this way ``` public cla...

Why are there no lifted short-circuiting operators on `bool?`?

Why are there no lifted short-circuiting operators on `bool?`? Why doesn't `bool?` support lifted `&&` and `||`? They could have lifted the `true` and `false` operators which would have indirectly add...

Can't operator == be applied to generic types in C#?

Can't operator == be applied to generic types in C#? According to the documentation of the `==` operator in [MSDN](http://msdn.microsoft.com/en-us/library/53k8ybth.aspx), > For predefined value types,...

Wrong compiler warning when comparing struct to null

Wrong compiler warning when comparing struct to null Consider the following code: With Visual Studio 2010 (C# 4, .NET 4.0), I get the following warning: > warning CS0458: The result of the expression ...

Define a generic that implements the + operator

Define a generic that implements the + operator > [Solution for overloaded operator constraint in .NET generics](https://stackoverflow.com/questions/147646/solution-for-overloaded-operator-constraint...

23 May at 11:54

Why does the == operator work for Nullable<T> when == is not defined?

Why does the == operator work for Nullable when == is not defined? I was just looking at [this answer](https://stackoverflow.com/a/5602820/129164), which contains the code for `Nullable` from .NET Ref...

Do short-circuiting operators || and && exist for nullable booleans? The RuntimeBinder sometimes thinks so

Do short-circuiting operators || and && exist for nullable booleans? The RuntimeBinder sometimes thinks so I read the C# Language Specification on the `||` and `&&`, also known as the short-circuiting...

Operator '=' chaining in C# - surely this test should pass?

Operator '=' chaining in C# - surely this test should pass? I was just writing a property setter and had a brain-wave about why we don't have to `return` the result of a `set` when a property might be...

12 Jul at 16:1

C# Error: The call is ambiguous between the following methods or properties. Overloading operators

C# Error: The call is ambiguous between the following methods or properties. Overloading operators I have 2 classes with overloaded operators in a namespace called Dinero, these are the 2 classes: Fir...

"?" type modifer precedence vs logical and operator (&) vs address-of operator (&)

"?" type modifer precedence vs logical and operator (&) vs address-of operator (&) It seems that I am not being clear enough of what exactly I am asking (and as the question developed over time I also...

2 Jun at 11:57

Reference Guide: What does this symbol mean in PHP? (PHP Syntax)

Reference Guide: What does this symbol mean in PHP? (PHP Syntax) ### What is this? This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki,...