如何将对象转换为Datatble C#?

问题描述:

我有一个C#方法,对象返回数据类型

喜欢这个



Hi , i have a C# method with the object return data type
like this

datatable Dt=new Datatable();

public object Method1()
{

return Dt;

}



当我尝试这样做但似乎错了!为什么?!


when i try to do this but it seems its wrong ! why?!

datatable A=new Datatble();
A=myobject.Method1();

你忘了做演员:)



You forgot to do the casting :)

// Instead of:
//   A=myobject.Method1();
// Do:
A = (Datatable)myobject.Method1();





*请参阅了解更多信息施放 [ ^ ]



干杯,

Edo



* See more about casting[^]

Cheers,
Edo


试试这个

try this
datatable A=new Datatble();
A=(DataTable)myobject.Method1();