Search This Blog

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.




GetRandomFileName C#

C# > Files > GetRandomFileName

GetRandomFileName returns a random cryptographically string that can be used as either a folder name or a file name. GetRandomFileName does not create a file.
 
Example:
string rndFile = Path.GetRandomFileName();







Monday, November 4, 2013

Working with files in C#

C# > IO

IO allow reading and writing to files and data streams, and types that provide basic file and directory support.

Directory class

Path methods
IO
Examples:





    String Type C#

    C# > Types > String

    String type represents a sequence of Unicode characters and is a reference type.

    Methods


    Example:

    string a = "Hello";
    string b = " world";
    // Append ! to contents of b
    b += "!";
    MessageBox.Show (a + b);




    What is C#






    C# is modern, multi-paradigm,  strongly-typed, object oriented  and high level programming language.
    C# is an elegant language that enables you to build a variety of secure and robust applications that run on the .NET Framework. With C# you can create Windows client or Web applications, XML Web services, distributed components, client-server applications, database applications, etc.

    The language of C# is very easy for anyone familiar with C, C++ or Java.
    System












    Reflection C#

    C# > Reflection 

    Reflection offers the possibility   to describe assemblies, modules and types. It enables you to access the attributes. 
    A compiled C# program is a relational database called metadata.


    Example:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace csharp
    {
        public partial class Form1 : Form
        {
            public static int mNumber = 10;
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                Type objType = typeof(Form1);
                FieldInfo field = objType.GetField("mNumber");
                object objValue = field.GetValue(null);
                MessageBox.Show(objValue.ToString());
            }
        }
    }