从vb转换为C# [英] Converted from vb to C#

查看:124
本文介绍了从vb转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我将一些代码从vb转换为c#.我在一条线上遇到麻烦:
mail = CreateObject("CDO.Message")这是vb代码.转换为C#后:
mail = Interaction.CreateObject("CDO.Message");
我收到错误消息在当前上下文中不存在名称交互."
我是否需要包括某种using指令?任何帮助将不胜感激.我看过Google,但运气不佳.

谢谢
D

Hi All, I converted some code from vb to c#. I am having troubles with one line:
mail = CreateObject("CDO.Message") this was the vb code. After converting to C#:
mail = Interaction.CreateObject("CDO.Message");
I am getting the error "The name interaction does not exist in the current context."
Do I need to include some sort of using directive or what? Any help would be greatly appreciated. I looked on Google, but did not have much luck.

Thank-you,
D

推荐答案

在这里看看:
http://stackoverflow.com/questions/3251308/createobject-equivalent-for-c-sharp-4-dynamic-keyword-and-late-binding [ http://social.msdn.microsoft.com/Forums/zh/csharpgeneral/thread/e7fb3c55-3b02-4c78-8f10-fa4d11f998e6 [
Have a look here:
http://stackoverflow.com/questions/3251308/createobject-equivalent-for-c-sharp-4-dynamic-keyword-and-late-binding[^]
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/e7fb3c55-3b02-4c78-8f10-fa4d11f998e6[^]


您可能没有添加对此类交互"的引用
you may didn''t add referance to this class ''Interaction''


为了使用Interaction类,您的C#项目必须具有对Microsoft.VisualBasic.dll的引用(请参见
In order to use the Interaction class, your C# project has to have a reference to Microsoft.VisualBasic.dll (see here[^]), which is a very heavy import for just one function.

The "proper" .NET way to do this is to use something like this (in .NET 4):
dynamic comObject = Activator.CreateInstance(Type.GetTypeFromProgID(typeName, true));


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

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