( snq- | 2006. 12. 17., v – 16:31 )

ne nyeld le a konstruktorban a kivételt


public class ConditionalObject
{
	public ConditionalObject(string name)
	{
		if (name == String.Empty)
		{
			throw new ArgumentException("name");
		}
		//todo
	}
}

public class CallerClass
{
	public static void Main()
	{
		ConditionalObject obj = null;
		try
		{
			obj = new ConditionalObject(String.Empty);
		}
		catch
		{
			//hoppa
		}
		Console.WriteLine(obj == null ? "null" : "not null");
	}
}

kimenet "" esetén: null, "T" esetén: not null