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

My Art is Showing at the Renaissance Center!

Everyone, I have three images showing this month at the Renaissance Center in Wake Forest NC, below is a link. The show runs from March 7 to April 2. You can purchase my prints online at: https://wade-brooks.pixels.com/collections/recent Gallery Info here: https://www.wakeforestrencen.org/event/march-art-exhibit-reception-wake-forest-camera-club Cheers, Wade

What Next?

 It's time. It's time to do something completely different. Starting in November, I will be retired from Cree/Wolfspeed where I have worked for over 27 years. I feel it is time to move on. With that said, I'd like to do something. Something other than software or database development. I'm not really sure what form it will take, but I am open to suggestions. I know that I don't want to sit at a desk all day. I'd like to do something that helps others or the environment. It doesn't have to be related to photography, but could be. If you have any ideas, let me know. Cheers, Wade

10 Books Rich People Read

“Think and Grow Rich” by Napoleon Hill “How to Win Friends and Influence People” by Dale Carnegie The Intelligent Investor” by Benjamin Graham “Zero to One” by Peter Thiel “The Lean Startup” by Eric Ries “Sapiens” by Yuval Noah Harari “The Hard Thing About Hard Things” by Ben Horowitz “Principles” by Ray Dalio “The Innovator’s Dilemma” by Clayton Christensen “Poor Charlie’s Almanack” compiled by Peter D. Kaufman