Click here to Skip to main content
15,894,180 members
Articles / Programming Languages / Visual Basic

Utilize VB.NET in C# Project

Rate me:
Please Sign up or sign in to vote.
1.75/5 (3 votes)
28 Oct 2013CPOL1 min read 15.4K   4   7
How to utilize VB.NET in C# project

Introduction

As some of you may know, I love C# and obviously the .NET Framework; however, I recently took on a new job doing VB.NET programming. I can honestly say I like VB.NET, or for that matter most programming languages that serve their purpose. Most server side programming projects I have been working on are strictly C#, but I want to practice VB.NET, while still working towards something that I can actually use (e.g., not programming strictly just for exercise but exercise and purpose to follow the 80/20 rule). In this brief post, we will efficiently go through how we can use VB.NET in a C# project.

DLLs Baby

The solution is rather simple: Create a VB.NET class library and class, add business logic to the class, and add a reference in our C# project to the VB.NET class library’s DLL to utilize it.

Simple VB.NET interface and implementation to get the ball rolling:

VB.NET
Namespace Brandrick.Services.BrandrickNetCSSEditor

    Public Interface IBrandrickNetCSSEditor
        'Update CSS Colors and return resource location
        Function UpdateColor(ByVal Red As Integer, _
        ByVal Green As Integer, ByVal Blue As Integer) As String

    End Interface

    Public Class BrandrickNetCSSEditor
        Implements IBrandrickNetCSSEditor

        Public Function UpdateColor(Red As Integer, Green As Integer, _
        Blue As Integer) As String Implements IBrandrickNetCSSEditor.UpdateColor
            'ToDo: Business Logic
            Return "CSS Resource"
        End Function
    End Class

End Namespace

Add a DLL reference from the VB.NET project to the C# project:

Add Reference

Utilize VB.NET code in C#:

C#
using Brandrick.Services;
using Brandrick.Services.VB.Brandrick.Services.BrandrickNetCSSEditor;
using System.Web;
using System.Web.Mvc;
namespace Brandrick.Controllers
{
    public class ThemeController : Controller
    {
        public ActionResult CreateCustomTheme(int red, int green, int blue)
        {
            IBrandrickNetCSSEditor bNetCSSEditor = new BrandrickNetCSSEditor();
            var resource = bNetCSSEditor.UpdateColor(red, green, blue);
            ViewBag.resource = resource;

            return View();
        }
    }
}

Conclusion

While the code is not complete in these examples, you see it is simple to utilize both VB.NET and C# in the same solution, which provides the option to pick your .NET programming language flavor within the same solution.

This article was originally posted at http://www.robbiebrandrick.com/Blog/Details/19

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
srilekhamenon2-Dec-14 1:23
professionalsrilekhamenon2-Dec-14 1:23 
Misleading article
GeneralJust OK Pin
Member 812274929-Nov-13 19:08
Member 812274929-Nov-13 19:08 
Question[My vote of 1] title is misleading Pin
VellaJ7-Nov-13 21:22
VellaJ7-Nov-13 21:22 
AnswerRe: [My vote of 1] title is misleading Pin
RobNO16-Nov-13 3:16
professionalRobNO16-Nov-13 3:16 
GeneralRe: [My vote of 1] title is misleading Pin
VellaJ17-Nov-13 13:39
VellaJ17-Nov-13 13:39 
GeneralRe: [My vote of 1] title is misleading Pin
RobNO18-Nov-13 15:27
professionalRobNO18-Nov-13 15:27 
GeneralRe: [My vote of 1] title is misleading Pin
VellaJ18-Nov-13 15:49
VellaJ18-Nov-13 15:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.