Skip to main content

Settings in C# and other lessons learned while converting from VB.Net

 I started converting some of my VB.Net code to C# and have learned a few things. Reading settings was my first stumbling block as there was a lot of incorrect information on the internet. I did finally get it to work and will summarize here.

I have a small application that loads engineering data into a SQL database. The files are basic text files with either XML or comma separated values. I store a few variables, such as path, file type, etc, in the app.config file. In VB it is simple to pull this info:

Path = My.Settings.Folder

In C#, the code is a little different. Here is my final working code for the above example:

 Path = [NameSpace].[AppName].Properties.Settings.Default.Folder;

For me, using the This keyword did not work.

I have also been using this website to convert each Method from VB to C# and have found it very helpful:

http://converter.telerik.com/

A couple of other items that tripped me up are all arrays need brackets, instead of parentheses. Also when you add Trim or ToString to a variable, in C# it needs parentheses at the end. Not a huge deal, but took me a minute to figure out.

Let me know if you have any other tricks or lessons learned to share.

Cheers,
Wade

Comments

Popular posts from this blog

Sunshine Reaching

With rays of warmth, he embraces her soul.  Arms, iron strong, surround their love. Sunshine reaching, fills the room.  With feathered whispers, they embrace the day. Poetry and picture by me. Picture taken in 2017 and re-edited today for this post. Cheers, Wade

What's in a Name

 A friend recently posted on social media the meaning of their name, which I thought was interesting. So I deciphered mine and came up with this: Traveler of heavenly waters, builder of ships .  This is my First, Last, Middle names deciphered thanks to the internet. I find this interesting since I love to be by water or in water. I also like to build things. I guess my name is a good name for me. Cheers, Wade PS. Here's some water, since I also like taking pictures. 😊

Matrix Rain Window

  I wanted a small application that would show a Matrix like rain window, so I converted C# code (link below) to VB.NET (links below). Original C# Code is here: http://www.codeproject.com/Articles/113227/Matrix-Rain My VB.Net Source Code: https://drive.google.com/open?id=0BxXnsiUlViylWkhTQ2dtclkwTFE My created executable file is here: https://drive.google.com/open?id=0BxXnsiUlViylU25KaG44NUpfTnc