可以通過返回異常的方式實現
public class Test
{
public Test(int a)
{
if (a<0)
{
throw new Exception("條件不符,不能實例化"); 
}
}
public string ShowString()
{
return("ABC");
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
Test t=new Test(-2);
MessageBox.Show(t.ShowString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}