7022041865

C#

byte a, b, c;
a = byte.MaxValue;   / a = 255 (11111111)
a >>= 3;             / a = 31  (00011111)
b = (byte)(a << 3);  / b = 248 (11111000)
c = (byte)~b;        / c = 7   (00000111)
c = (byte)(a & b);   / c = 24  (00011000)
c = (byte)(a | b);   / c = 255 (11111111)
c = (byte)(a ^ b);   / c = 231 (11100111)

304-308-4474

C#

using System.Windows;
namespace MyNamespace {
    public partial class MainWindow : Window {
        public string MyText {
            get;set;
        }
        public MainWindow() {
            MyText = "New text for binding.";
            InitializeComponent();
        }
    }
}


XAML

<Window x:Class="MyNamespace.MainWindow"
        xmlns="/schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="/schemas.microsoft.com/winfx/2006/xaml"
        Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="{Binding Path=MyText}">
    <Grid>
        <TextBox Text="{Binding Path=MyText}"/>
    </Grid>
</Window>

Only one running application

C#

static class Program { 
    static Mutex mutex = new Mutex(true, "{cca774e1-af6b-46e7-9207-27adbff85648}"); 
    [STAThread] 
    static void Main() { 
    if (mutex.WaitOne(TimeSpan.Zero, true)) { 
        Application.EnableVisualStyles(); 
        Application.SetCompatibleTextRenderingDefault(false); 
        Application.Run(new MyApplication()); 
        mutex.ReleaseMutex(); 
    } 
    else 
        MessageBox.Show("The application is already running.", "MyApplication"); 
        mutex.Dispose(); 
    } 
}

Read from Web Stream

C#

static byte[] ReadFromUrl(string url) { 
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
    HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
    Stream stream = response.GetResponseStream(); 
    List<byte> fileBytes = new List<byte>(); 
    while (stream.CanRead) { 
        int fileByte = stream.ReadByte(); 
        if (fileByte < 0) 
            break; 
            fileBytes.Add((byte)fileByte); 
        } 
    stream.Close(); 
    stream.Dispose(); 
    response.Close(); 
    response.Dispose(); 
    return fileBytes.ToArray(); 
}

Operators

Primary

x.m             Member access
x(...)          Method and delegate invocation
x[...]          Array and indexer access
x++             Post-increment
x--             Post-decrement
new T(...)      Object and delegate creation
new T(...){...} Object creation with initializer
new {...}       Anonymous object initializer
new T[...]      Array creation
typeof(T)       Obtain Type object for T
checked(x)      Evaluate expression in checked context
unchecked(x)    Evaluate expression in unchecked context
default(T)      Obtain default value of type T
delegate {...}  Anonymous function (anonymous method)

Unary

+x              Identity
-x              Negation
!x              Logical negation
~x              Bitwise negation
++x             Pre-increment
--x             Pre-decrement
(T)x            Explicitly convert x to type T
await x         Asynchronously wait for x to complete

Multiplicative

x * y           Multiplication
x / y           Division
x % y           Remainder

Additive

x + y           Addition, string concatenation, delegate combination
x – y           Subtraction, delegate removal

Shift

x << y          Shift left
x >> y          Shift right

Relational and type testing

x < y           Less than
x > y           Greater than
x <= y          Less than or equal
x >= y          Greater than or equal
x is T          Return true if x is a T, false otherwise
x as T          Return x typed as T, or null if x is not a T

Equality

x == y          Equal
x != y          Not equal

Logical AND

x & y           Integer bitwise AND, boolean logical AND

Logical XOR

x ^ y           Integer bitwise XOR, boolean logical XOR

Logical OR

x | y           Integer bitwise OR, boolean logical OR

Conditional AND

x && y          Evaluates y only if x is not false

Conditional OR

x || y          Evaluates y only if x is not true

Null coalescing

x ?? y          Evaluates to y if x is null, to x otherwise

Conditional

x ? y : z       Evaluates y if x is true, z if x is false

Assignment or anonymous function

x = y           Assignment
x op= y         Compound assignment; supported operators are *= /= %= += -= <<= >>= &= ^= |=
(T x) => y      Anonymous function (lambda expression)

2103470055

Value types

  • Simple Types
    • Signed Integral
      • sbyte: 8 bits, range from -128 to 127
      • short: 16 bits, range from -32768 to 32767
      • int : 32 bits, range from -2147483648 to 2147483647
      • long : 64 bits, range from –9223372036854775808 to 9223372036854775807, suffix l or L
    • Unsigned integral
      • byte : 8 bits, range from 0 to 255
      • ushort : 16 bits, range from 0 to 65535
      • uint : 32 bits, range from 0 to 4294967295, suffix u or U
      • ulong : 64 bits, range from 0 to 18446744073709551615, suffix ul or UL
    • Unicode characters
      • char : 16 bits, U0000 – UFFFF
    • Floating point
      • float : 32 bits, range from ±1.401298×10⁻⁴⁵ to ±3,402823×10⁺³⁸, 7-digit precision, suffix f or F
      • double : 64 bits, range from ±9.881313E⁻³²⁴ to ±1.797693×10⁺³⁰⁸, 15-digit precision, suffix d or D
    • Decimal
      • decimal : 128 bits, range from ±1.000000×10⁻²⁸ to ±7.922816×10⁺²⁸, 28-digit precision, suffix m or M
    • Boolean
      • bool : 8 bits, false – true
  • Enum types
    • User-defined types of the form enum E {…}
  • Struct types
    • User-defined types of the form struct S {…}
  • Nullable value types
    • Extensions of all other value types with a null value

Reference types

  • Class types
    • Ultimate base class of all other types: object
    • Unicode strings: string
    • User-defined types of the form class C {…}
  • Interface types
    • User-defined types of the form interface I {…}
  • Array types
    • Single- and multi-dimensional, for example, int[] and int[,]
  • Delegate types
    • User-defined types of the form delegate int D(…)

 

 

WPF binding properties

C#

public partial class MyControl : UserControl, INotifyPropertyChanged { 
    string _MyProperty; 
    public string MyProperty { 
        get { 
            return _MyProperty; 
        } 
        set { 
            _MyProperty = value; 
            OnPropertyChanged(); 
        } 
    } 
    public UserControl() { 
        InitializeComponent(); 
        DataContext = this; 
    } 
    public event PropertyChangedEventHandler PropertyChanged; 
    protected void OnPropertyChanged([CallerMemberName]string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
}


XAML

<UserControl x:Class="MyControl"> 
    <TextBox Text="{Binding Path=MyProperty}"/> 
</UserControl>

 

781-898-4575

C#

public class MyEventArgs : EventArgs { 
    string _MyArgument; 
    public string MyArgument { 
        get { 
            return _MyArgument; 
        } 
    } 
    public MyEventArgs(string MyArgument) { 
        _MyArgument = MyArgument; 
    }
} 
public delegate void MyEventHandler(object sender, MyEventArgs e); 
public event MyEventHandler MyEvent; 
protected void OnMyEvent(string argument) => MyEvent?.Invoke(this, new MyEventArgs(argument));