在C#中使用vb.net类 [英] Using vb.net classes in c#

查看:266
本文介绍了在C#中使用vb.net类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建在vb.net类型和使用C#中的类型? 我想我需要编译VB项目并添加引用的DLL,但不知道如果这是正确的方式做到这一点,或参考将是有效的。 这样做是不是为了好玩,我们有一些VB code和我们正在考虑这个选项。

How can I create a type in vb.net and use the type in c#? I guess I need to compile the vb project and add reference to the dll but have no idea if this is the right way to do it, or the reference will be valid. Doing this is not for fun, we have some vb code and we're considering this option.

推荐答案

只要创建在VB一个类库项目,然后从C#项目引用添加到该项目。 (或者,如果它是在一个不同的解决方案,添加一个引用到由VB项目创建的DLL)。它应该是绝对没问题 - 你将有机会获得所有的公开类型从你的类库。

Just create a Class Library project in VB, and then add a reference to that project from your C# project. (Or if it's in a different solution, add a reference to the DLL created by the VB project.) It should be absolutely fine - you'll have access to all the Public types from your class library.

要解决你的问题的意见,这些项目的可以的默认值都是同一个命名空间,但它通常是一个好主意,使每一个项目都有自己的命名空间,所以很明显,其中任何特定类型得来的。

To address the comment in your question, the projects can both default to the same namespace, but it's generally a better idea to make each project have its own namespace, so it's clear where any particular type comes from.

这篇关于在C#中使用vb.net类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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