开发者

how to access class and its functions from another class

This is my first major application using multiple classes. It is written in vb and I know about creating objects of the class and using that instance to call functions of the class. But how do I create an object with constructors to allow another program written开发者_如何学JAVA in C# to access my classes and functions and accept things from the program.

Hope this makes sense.


Simply create a .NET class library and include that library as a reference inside the C# program. In .NET all libraries are .DLL files.

Once you do that the library will be available to C# with C# syntax.


You need to compile your VB classes into a class library (DLL) not an application.

From you C# application you need to add a reference to your newly compiled DLL. This DLL contains the classes and methods that you can instantiate and call from C#.

Once you've added a reference to the VB DLL from your C# assembly, you can access the VB classes (mostly) as though they were all in the same assembly. (I say mostly because access modifiers can change this, especially the 'internal' access modifier).


Dim myClassInstance As New MyClass()

edit: Ah, you want to define a class with constructors? If that is the case, try this:

Public Class MyClass
    Public Sub New(myNumber As Integer) 'Defines a constructor with an Integer as argument
    End Sub
End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜