Search This Blog

Wednesday, November 6, 2013

sbyte keyword C#

C# > Types > sbyte

The sbyte keyword is an integral type.
Range: -128 to 127
Size: Signed 8-bit integer

Example:

sbyte k = 127; // ok
k = 128;      // Error     1      Constant value '128' cannot be converted to a 'sbyte' 





int keyword C#

C# > Types > int

The int keyword is an integral type.
Range: -2,147,483,648 to 2,147,483,647
Size: Signed 32-bit integer

Example:

int i = 100;

int x = 3.0; // Error 1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

int y = (int)3.0; // OK: explicit conversion.





Stopwatch C# Example

C# > Diagnostics > Stopwatch 

Stopwatch measures elapsed time.

The Stopwatch measures elapsed time by counting timer ticks in the timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time.

Example:


Stopwatch sw = new Stopwatch();
sw.Start();
Thread.Sleep(500);
sw.Stop();
TimeSpan ts = sw.Elapsed;
MessageBox.Show("Elapsed time " + ts.ToString());





C# operators

C# > Operators

C# operators are symbols that specify which operations to perform in an expression.










InteropServices C#

C# > InteropServices

InteropServices namespace provides members that support COM interop and platform invoke services.

The .NET Framework allows interaction with COM components, COM+ services and external type libraries.
Managed code executes under the control of the runtime.
Unmanaged code runs outside the runtime. COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code.












Tuesday, November 5, 2013

Abstract C#

C# > Keywords > abstract

Abstract  indicates that a class is intended only to be a base class of other classes.
Abstract classes features:
  • cannot be instantiated.
  • may contain abstract methods and accessors.
  • it is not possible to modify an abstract class with the sealed modifier
  • class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
Example:

    public abstract class Shape
    {
        public abstract int Area();
    }
    public class Rectangle : Shape
    {
        int x = 0;
        int y = 0;
        public Rectangle(int _x, int _y)
        {
            x = _x;
            y = _y;
        }
        public override int Area()
        {
            return x * y;
        }
    }

    Rectangle rct = new Rectangle(10, 20);
    int area = rct.Area();












Modifiers C#

C# > Modifiers

Modifiers are used to modify declarations of types and type members.