Working with my current client, I took their complete VB Windows Forms application and ran it through a tool that purports to convert VB to C#. Remembering my transition, I've come up with a list of things you can do in your VB programming to ease your transition to C# today.
C# doesn't allow you get away with as many bad programming practices. Making the switch was a little painful at first because I realized how much sloppy coding Visual Basic lets you get away with. I then programmed in both for a couple of years, but then switched completely to C#. I started programming Visual Basic right when VB 3.0 came out. In this article, I'll take you through the process my team and I have come up with to make the conversion much easier. They have a very large Windows Forms application that they've committed to converting to C#. How do you prepare for converting your VB applications to C#? I'm currently helping one company do that. Right or wrong as that might be, you can't fight the trend. Programmers don't want to keep working in what are viewed as legacy technologies. If you currently have VB applications, and your current programmer(s) quit, you're going to be hard-pressed to replace them. NET applications, but it's just not the cool kid down the block anymore. Visual Basic is a perfectly good language for creating. As we all see when searching the Web, there are more samples in C# than there are in VB. finalResult = yourMessage.It seems that more programmers are switching to C# from Visual Basic (VB) than ever before. It takes two parameters, the old string and new string, and it can also take chars. In the following example, the spaces in yourMessage are removed and replaced with dashes. The replace method replaces a string with another string. Example finalResult = yourMessage.ToUpper()įinalResult = yourMessage.ToLower() Replace The ToUpper and ToLower converts a string either to uppercase or lowercase format. Dim yourMessage As String = "Welcome to thecodingguys"įor the sake of brevity we have omitted the Console.WritelIne(finalResult), from the examples however if you want to add it, remember to add the Console.ReadLine() as well. In the following examples we will be working with a string called yourMessage which will have the text “Welcome to thecodingguys”, and another string finalResult which is set to nothing. In the next few examples, you will see a few useful methods used to manipulate strings. For example, you can format a string and make it all uppercase, you can remove spaces, or you can simply count the length of the string. There are many built-in methods available to you, so you can format strings in a number of ways. In this example, the first parameter (myNumber) would appear as £158 and the second one would appear as 25%. StrFormat = String.Format("", myNumber, mySecondNumber) Net Framework becomes useful, as it can detect the user’s country / regional settings and format the piece of text to match those settings. For example, say you wrote Console.WriteLine (“Your balance is £5″) however, if you gave this away to someone in the USA or Italy, they would see the British pound symbol instead of their own country’s currency symbol. The string.format method is useful for formatting your text, and you can format it in many ways. This will print out “thecodingguys is awesome”. For example: Console.WriteLine(myName & " is awesome") You use the & ( or + ) to form a concatenation. It can be very useful when you want to link something together to form a sentence. Concatenation means joining two things together, in this case joining strings.