using VB.NET classes in C#

I

irfan

hi,

can anyone tell me how could I use the VB.NET classes
within my C#?

I tried doing the same, but in vain. I have a VB.NET class
in a VB.NET project. It has the same name for the
namespace as for the C# class. It compiled. But my C#
project does not recognize it when I try calling it.
Moreover, I'm unable to see the VB.NET class within C#.

Kindly correct me with the correct procedure of doing
this..

thanks,
irfan
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

1. Reference the assembly containing the VB .NET class from the C# project
2. Add a "using" statement that would import that VB .NET class' namespace
(if it differs from the one used in the C# class importing the VB .NET one)
to the file containing the C# class.
3. The VB .NET class should become pretty visible in the C# project.
 
I

irfan

Hi Dmitriy Lapshin,

first of all, thanx a ton for ur reply..

here's the code I use

VB.NET

Namespace MyNamespace
Public Class CVB
Public Sub CVB()

End Sub

Function vbFun(ByVal name As String) As String
vbFun = name.ToUpper()
End Function

End Class
End Namespace

C#
using System;

namespace MyNamespace
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class CClass
{
public CClass()
{
//
// TODO: Add constructor logic here
//
}
public string myMethod()
{
CVB cc = new CVB();
return cc.vbFun("irfan");
}

}
}

I am unable to compile and generate an assembly for the vb
class.

Inorder to use vb class in C#, I should create an assembly?

TIA
irfan
 
A

Andreas =?ISO-8859-1?Q?M=FCller?=

irfan said:
Hi Dmitriy Lapshin,

first of all, thanx a ton for ur reply..

here's the code I use

VB.NET

Namespace MyNamespace
Public Class CVB
Public Sub CVB()

End Sub

Function vbFun(ByVal name As String) As String
vbFun = name.ToUpper()
End Function

End Class
End Namespace

C#
using System;

namespace MyNamespace
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class CClass
{
public CClass()
{
//
// TODO: Add constructor logic here
//
}
public string myMethod()
{
CVB cc = new CVB();
return cc.vbFun("irfan");
}

}
}

I am unable to compile and generate an assembly for the vb
class.

Inorder to use vb class in C#, I should create an assembly?

TIA
irfan

By default, VB adds a namespace around the assemblies content that is
usually the name of the VB Assembly. You can find that under project
properties->common properties->general->root namespace
so you either can remove this or use your VB class like this:
YourVbAssembly.MyNamespace.CVB c = new YourVbAssembly.MyNamespace.CVB()

HTH,
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top