如何将对象转换为Datatble C#? [英] How to convert object to a Datatble C#?

查看:107
本文介绍了如何将对象转换为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();


这篇关于如何将对象转换为Datatble C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆