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

Artist Friend's Art Links

 A few links from artist friends I know: Sue Buehler https://www.subuehler.com Kathleen Kent https://www.kathleenlkent.com/ Lora Lee Chapman http://www.llchapman.com Heather Szarka https://authenticsuperior.com/shop/heather-szarka-photography Swee Oh https://www.sweecoh.com/ David Robinson https://davidrrobinson.pixels.com/ Gary Paakkonen https://www.garypaakkonen.com/ Katie Wright https://www.redbubble.com/people/TinyCameraNinja/shop Lauri Novak https://laurinovak.com/exclusively-through-lauri-novak/ And here's one of my pics, just for fun!

Gallery Show Prints

Check out my post about my art in the upcoming 311 Gallery show.  https://www.artbywade.com/2022/11/gallery-show-prints.html