here is the example which shows how we can achieve cross language environment in dotnet
1. First we make a dll in VB.net
2. and after that we use this VB.net's dll in c# (here we achieving cross language environment)
lets try it:
program to making dll in vb.net
//we are saving this program as SampleVBDll.vb
imports System
public class test
public function show_data() as string
return "hello Csharp"
end function
end class
Complie this as: c:\>vbc /t:library SampleVBDll.vb (this is command to making a dll in vb.net)
and it gives us "SampleVBDll.dll" later on we use this dll as reference while compling the csharp program
//in this program we are using the VB .net dll in csharp program
//This program name is 'demo.cs'
using System;
class demo:test //here we inherit class test in our class demo
{
public static void Main()
{
test t = new test(); //here i am making the object of test class which is in 'SampleVBDll'
string f = t.show_data(); //and here we are calling the function(show_data) of class 'test' which
// is in 'SampleVBDll'
Console.WriteLine(f);
}
}
Compile this as: c:\>csc /r:SampleVBDll.dll demo.cs
and this give us 'demo.exe' and output is below
OUTPUT:
hello Csharp
1. First we make a dll in VB.net
2. and after that we use this VB.net's dll in c# (here we achieving cross language environment)
lets try it:
program to making dll in vb.net
//we are saving this program as SampleVBDll.vb
imports System
public class test
public function show_data() as string
return "hello Csharp"
end function
end class
Complie this as: c:\>vbc /t:library SampleVBDll.vb (this is command to making a dll in vb.net)
and it gives us "SampleVBDll.dll" later on we use this dll as reference while compling the csharp program
//in this program we are using the VB .net dll in csharp program
//This program name is 'demo.cs'
using System;
class demo:test //here we inherit class test in our class demo
{
public static void Main()
{
test t = new test(); //here i am making the object of test class which is in 'SampleVBDll'
string f = t.show_data(); //and here we are calling the function(show_data) of class 'test' which
// is in 'SampleVBDll'
Console.WriteLine(f);
}
}
Compile this as: c:\>csc /r:SampleVBDll.dll demo.cs
and this give us 'demo.exe' and output is below
OUTPUT:
hello Csharp
No comments:
Post a Comment