Safe mode in D?

Max Samukha maxsamukha at gmail.com
Fri Oct 18 15:29:43 PDT 2013


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);
		}
	}
}













More information about the Digitalmars-d mailing list