locked
c++ or any other language in c# RRS feed

  • Question

  • Hi

    i was not sure whre to post this...


    i use c# (in visual studio 2005) but I would like to know if it is not possible to create a class in a different laguage in a c# application

    for example if my friend writes a c++ class I want to use and acces it with C# code

    so can a make a region of code be in anoter language while my main program is in c#?

     is this possible at all?

    thanks szsz

    Sunday, March 18, 2007 7:40 PM

Answers

  • You can compile your friends class into a "Class Library" which means it is compiled into its own assembly as a DLL file. Then you can add a reference to the DLL file from your project and put a using statement at the top of your class files to access your friend's class.

    For example, your friend writes a class called FriendClass in the FriendNamespace which is compiled to FriendNamespace.DLL.

    You can then put the DLL on your computer in the same directory as your compiled program goes, or in the GAC. You tell your project that it "References" the DLL file (the "assembly").

    In your project you have a class called MyClass. The file should look like this:

    using FriendNameSpace;
    namespace MyNameSpace
    {
         class MyClass
         {
              FriendClass fc = new FriendClass();

              protected void UseMyFriendsClass()
              {
                    fc.DoSomethingThatMyFriendWrote();
              }
         }
    }

    Monday, March 19, 2007 12:55 AM