Am 19.10.2013 00:29, schrieb Max Samukha:
On Friday, 18 October 2013 at 20:03:22 UTC, Maxim Fomin wrote:

(By the way, I don't see why the code above provoked you to C#
talks).

Because you:

1) Mentioned C# as a safer alternative to D.
2) Are using reflection to demonstrate D's unsafety.

Try this:

using System;
using System.Reflection;

namespace test
{
     class A
     {
         public int x;
         public A()
         {
             x += 1;
         }
     }

     class App
     {
         public static void Main (string[] args)
         {
             var a = new A();
             var ctor = a.GetType().GetConstructor(new Type[] {});
             ctor.Invoke(a, new object[] {});
             ctor.Invoke(a, new object[] {});
             Console.Write(a.x);
         }
     }
}



There is nothing unsafe about this code snippet.

--
Paulo

Reply via email to