积极答复者
请教vb.net转C#

问题
-
以下vb.net在转为C#时提示处:“object”不包含“AttrsEx1”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“AttrsEx1”(是否缺少 using 指令或程序集引用?)
请问要如何修改?谢谢
Public Function getAttr(ByVal obj As Object, ByVal attr_name As String) As Object Dim attrs As Object Dim attr As IAttribute attrs = obj.AttrsEx1(True, False) Dim i As Integer For i = 0 To UBound(attrs) attr = attrs(i) If attr.Name = attr_name Then Return attr End If Next Return Nothing End Function
IAttribute getAttr(object obj, string attr_name) { var attrs = obj.AttrsEx1(true, false); //转C#此处提示:“object”不包含“AttrsEx1”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“AttrsEx1”(是否缺少 using 指令或程序集引用?) foreach (var attr in attrs) { if (attr.Name = attr_name) return attr; } }
答案
-
Hi leon1526,
感谢你在MSDN论坛发帖。
对于缺少using,你可以把鼠标放在定义的类型上面,然后按下ctrl+.,就知道要添加什么using, 这是visual studio自带的功能,如下图:
根据你的错误信息,我个人觉得不是缺少using,应该是这个object不包含这个方法,所以使用不成功。object 类是.NET Framework 中最基本的类,根据我的调查,没有包含你说的那个方法。
关于object的详细信息,可以参考下面链接
https://msdn.microsoft.com/en-us/library/system.object_methods(v=vs.110).aspx
Best Regards,
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已标记为答案 leon1526 2017年6月22日 12:03
全部回复
-
Hi leon1526,
感谢你在MSDN论坛发帖。
对于缺少using,你可以把鼠标放在定义的类型上面,然后按下ctrl+.,就知道要添加什么using, 这是visual studio自带的功能,如下图:
根据你的错误信息,我个人觉得不是缺少using,应该是这个object不包含这个方法,所以使用不成功。object 类是.NET Framework 中最基本的类,根据我的调查,没有包含你说的那个方法。
关于object的详细信息,可以参考下面链接
https://msdn.microsoft.com/en-us/library/system.object_methods(v=vs.110).aspx
Best Regards,
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已标记为答案 leon1526 2017年6月22日 12:03
-
试下这个工具
VBConversions VB dotNET to CSharp Converter 5.01
http://www.0daydown.com/06/551304.html
专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms