110,476
社区成员
发帖
与我相关
我的任务
分享
public static void Method(Action action)
{
using (TestClass obj = new TestClass())
{
try
{
action(); //这里的委托将来的方法中 我还想使用上边using出来的obj对象 应该怎么封装这个方法啊
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void Method(Action<TestClass> action)
{
using (TestClass obj = new TestClass())
{
try
{
action.Invoke(obj);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}