&
and *
have multiple meanings in c#; including a double meaning when used as operators.
For information on how to use them as operators you can go to https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/
Option 1. Logical operators
&
, *
and ^
can all be used as logical operators. For example:
// Logical exclusive-OR
// When one operand is true and the other is false, exclusive-OR
// returns True.
bool b1 = true;
bool b2 = false;
Console.WriteLine(b1 ^ b2);
// When both operands are false, exclusive-OR returns False.
bool b1 = false;
bool b2 = false;
Console.WriteLine(b1 ^ b2);
// When both operands are true, exclusive-OR returns False.
bool b1 = true;
bool b2 = true;
Console.WriteLine(b1 ^ b2);
Option 2. Pointers
&
and *
can be used with pointers in c#.
From * Operator (C# Reference):
also serves as the dereference operator, which allows reading and writing to a pointer.
From & Operator (C# Reference)
The unary & operator returns the address of its operand (requires unsafe context).
There are some examples with both *
and &
in the Pointer types (C# Programming Guide)
// Normal pointer to an object.
int[] a = new int[5] { 10, 20, 30, 40, 50 };
// Must be in unsafe code to use interior pointers.
unsafe
{
// Must pin object on heap so that it doesn't move while using interior pointers.
fixed (int* p = &a[0])
{
// p is pinned as well as object, so create another pointer to show incrementing it.
int* p2 = p;
Console.WriteLine(*p2);
...more here...
How to search :)
I just put c# ^
in my fav search engine and got to the docos.
Here's the proof :)
