tagged [operators]

Is there any performance difference between ++i and i++ in C#?

Is there any performance difference between ++i and i++ in C#? Is there any performance difference between using something like ``` for(int i = 0; i

22 Jan at 13:36

Is a += 5 faster than a = a + 5?

Is a += 5 faster than a = a + 5? I'm currently learning about operators and expressions in C# and I understood that if I want to increment the value of a variable by 5, I can do it in two different wa...

1 Apr at 11:5

Is there a C# IN operator?

Is there a C# IN operator? In SQL, you can use the following syntax: Is there an equivalent in C#? The IDE seems to recognise "in" as a keyword, but I don't seem to be able to find any information on ...

2 Jul at 11:14

How can "x & y" be false when both x and y are true?

How can "x & y" be false when both x and y are true? ## Context: I'm learning C# and have been messing about on the [Pex for fun](http://pexforfun.com/) site. The site challenges you to re-implement a...

PowerShell and the -contains operator

PowerShell and the -contains operator Consider the following snippet: You’d think this evaluates to `true`, but it doesn't. This will evaluate to `false` instead. I’m not sure why this happens, but it...

List<T> operator == In the C# Language Specification Version 4

List operator == In the C# Language Specification Version 4 In the C# Language Specification Version 4, 1.6.7.5 Operators is information about `List` operators: `==` and `!=`. But I can't find such op...

13 Aug at 10:46

C# XOR on two byte variables will not compile without a cast

C# XOR on two byte variables will not compile without a cast Why does the following raise a compile time error: 'Cannot implicitly convert type 'int' to 'byte': This would make sense if I were using a...

28 Apr at 04:57

Why does the C# compiler translate this != comparison as if it were a > comparison?

Why does the C# compiler translate this != comparison as if it were a > comparison? I have by pure chance discovered that the C# compiler turns this method: …into this [CIL](http://en.wikipedia.org/wi...

19 Jul at 08:30

Operator as and generic classes

Operator as and generic classes I want to make a method: to accept a generic parameter: ``` T Execute() { return Execute() as T; /* doesn't work: The type parameter 'T' cannot be used with the '...

14 Nov at 01:29

Getting each individual digit from a whole integer

Getting each individual digit from a whole integer Let's say I have an integer called 'score', that looks like this: Now what I want to do is get each digit 1, 5, 2, 9, 5, 8, 7 from the score (See bel...

5 May at 15:20

Java logical operator short-circuiting

Java logical operator short-circuiting Which set is short-circuiting, and what exactly does it mean that the complex conditional expression is short-circuiting? ``` public static void main(String[] ar...

17 Jul at 23:33

How does the '&' symbol in PHP affect the outcome?

How does the '&' symbol in PHP affect the outcome? I've written and played around with alot of PHP function and variables where the original author has written the original code and I've had to contin...

16 Jun at 02:23

What does '&' do in a C++ declaration?

What does '&' do in a C++ declaration? I am a C guy and I'm trying to understand some C++ code. I have the following function declaration: ``` int foo(const string &myname) { cout

18 Oct at 04:43

C# - what does the unary ^ do?

C# - what does the unary ^ do? I have checked out some code and I got an error ('invalid expression term "^"' to be exact) in the line I have never seen a unary caret operator (I am only aware of the ...

3 Mar at 08:8

What's the difference between equal?, eql?, ===, and ==?

What's the difference between equal?, eql?, ===, and ==? I am trying to understand the difference between these four methods. I know by default that `==` calls the method `equal?` which returns true w...

8 Sep at 16:34

What does the ?. mean in C#?

What does the ?. mean in C#? From the project `Roslyn`, file `src\Compilers\CSharp\Portable\Syntax\CSharpSyntaxTree.cs` at line `446` there is: What is the `?.` there? Does it check whatever oldTree i...

18 Apr at 19:27

What is the difference between i = i + 1 and i += 1 in a 'for' loop?

What is the difference between i = i + 1 and i += 1 in a 'for' loop? I found out a curious thing today and was wondering if somebody could shed some light into what the difference is here? After runni...

3 Jan at 19:1

Operator overloading?

Operator overloading? I've made myself a rss reader that keeps me up to date and informs me on new shows, or atleast thats the thought behind. I've made a struct "SeasonEpisode" that hold two ints (se...

15 Apr at 06:6

What does the percentage sign mean in Python

What does the percentage sign mean in Python In the tutorial there is an example for finding prime numbers: I under

7 Jul at 10:35

?: Operator Vs. If Statement Performance

?: Operator Vs. If Statement Performance I've been trying to optimize my code to make it a little more concise and readable and was hoping I wasn't causing poorer performance from doing it. I think my...

Why do C#'s binary operators always return int regardless of the format of their inputs?

Why do C#'s binary operators always return int regardless of the format of their inputs? If I have two `byte`s `a` and `b`, how come: produces a compiler error about casting byte to int? It does this ...

23 May at 11:46

Using the ternary operator for multiple operations

Using the ternary operator for multiple operations How can I use the ternary `? :` condition to perform multiple operations, if expression is true/false? `wbsource = (exp) ? (Do one thing) : (Do secon...

8 Mar at 11:14

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

xor with 3 values

xor with 3 values I need to do an xor conditional between 3 values, ie i need one of the three values to be true but not more than one and not none. I thought i could use the xor ^ operator for this b...

3 Jun at 14:19

Is this big complicated thing equal to this? or this? or this?

Is this big complicated thing equal to this? or this? or this? Let's say I'm working with an object of class `thing`. The way I'm getting this object is a bit wordy: I'd like to see if this `thing` is...

7 Jun at 03:9