本文介绍了保持对象null比实现Idisposable Interface更好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace A1
{
class A
{
public int m;
public int n;
public int F(A a)
{
a.m = 50;
a.n = 40;
return (a.m*a.n);
}
}
}
using A1;
namespace try_catch_Idisposabe
{
class B
{
public static void Main(string[] args)
{
A a1=new A();
try
{
a1.m = 10;
a1.n = 30;
int l = a1.F(a1);
Console.WriteLine(l);
}
catch
{
}
finally
{
a1=null;
}
}
}
}
推荐答案
public static void main()
{
using(A objA = new A())
{
//Your code related to object goes here.
}
}
探索使用声明。
与您的搜索相关的问题在这里......
[]
希望这个帮助
-----------------
Pratik Bhuva
Explore about using statement.
the question related to your search is here...
http://stackoverflow.com/questions/567138/when-should-i-use-using-blocks-in-c[^]
Hope This Help
-----------------
Pratik Bhuva
这篇关于保持对象null比实现Idisposable Interface更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!