Popular Posts
SwiXml - Layout BorderLayout BorderLayoutPane.xml <?xml version="1.0" encoding="UTF-8"?> <panel layout="BorderLayout... android.intent.action.SCREEN_ON & android.intent.action.SCREEN_OFF First, I've tried create a receiver to receive screen on/off and register receiver on AndroidManifest.xml like below, but unfortunately ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Stats
new operator/modifier/constraint

new Operator Used to create objects and invoke constructors.

// Create objects and invoke constructors
Class1 obj  = new Class1();

// Create instances of anonymous types
var employee = new { EmpID = 3, Name = "Bruce", Gender = Gender.Male};

// invoke the default constructor for value types
int i = new int();

// invoke the default constructor for value types with default value
int i = 0;

new Modifier Used to hide an inherited member from a base class member.

class ParentClass
{
    public int x = 5;
    public void Work()
    {
        for (int i = 0; i < x; i++) Console.WriteLine("Parent work : " + i);
    }
    public decimal Caculate()
    {
        return x + x;
    }
}

class ChildClass : ParentClass
{
    public new int x;
    public new void Work()
    {
        for (int i = 0; i < x; i++) Console.WriteLine("Child work : " + i);
    }
    public new decimal Caculate()
    {
        return base.x + this.x;
    }
}

class Program
{
    static void Main(string[] args)
    {
        ParentClass p = new ParentClass();
        p.Work();
        // Parent work : 0
        // Parent work : 1
        // Parent work : 2
        // Parent work : 3
        // Parent work : 4
        Console.WriteLine(p.Caculate());
        // 10

        Console.WriteLine("================");

        ChildClass c = new ChildClass() { x = 3 };
        c.Work();
        // Child work : 0
        // Child work : 1
        // Child work : 2
        Console.WriteLine(c.Caculate());
        // 8
    }
}

new Constraint Used to restrict types that might be used as arguments for a type parameter in a generic declaration.

class MyCollection<T> where T : new()
{
    // Type T must have a public parameterless constructor
}

class MyCollection2<T> : IEnumerable<T> where T : IDisposable, new()
{
    // Type T implements IDisposable and must have a public parameterless constructor,
    // the new() constraint must at last
}