Apoorv
Apoorv

Reputation: 2043

C# equivalent for these VB statements

I am looking for the C# alternatives for these statements which were in VB and have been converted to C# using Telerik online convertor . The compiler gives error as it is unable to identify these statements.

Upvotes: 0

Views: 1024

Answers (4)

Dave Doknjas
Dave Doknjas

Reputation: 6542

Part of the problem is that your converter likely did not correctly convert the original Settings.Designer.vb file.

The original would normally be structured like this:

Partial NotInheritable Class Settings
    Inherits Global.System.Configuration.ApplicationSettingsBase
    ...
End Class

But your C# file should be structured like the following to get the previous suggestions to work:

namespace YourRootNamespace //project-level original VB 'root' namespace, if you have one
{
    namespace Properties
    {
        internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
        {
            ...
        }
    }
}

Now the suggestions about using 'Properties.Settings.Default' will work.

Also, at the bottom of that class, VB includes a module 'MySettingsProperty' in the 'My' namespace - just remove this (this just allowed the 'Settings' class to be included in the 'My' namespace).

Upvotes: 2

Sandip Patel
Sandip Patel

Reputation: 66

Properties.Settings.Default.Reload();

Properties.Settings.Default.MainScreenLeft = this.Left;

Properties.Settings.Default.MainScreenTop = this.Top;

Properties.Settings.Default.MainScreenWidth = this.Width;

Properties.Settings.Default.Save();
Properties.Settings.Default.Mode = CboMode.SelectedItem.ToString();

Upvotes: 1

Ash
Ash

Reputation: 6035

There's no direct translation for My in C#. This link gives details on using VB's My class in C#:

https://msdn.microsoft.com/en-us/library/ms173136.aspx

Since you're trying to access the settings of the project using Settings, try replacing My.Settings. in your statements with Properties.Settings.Default.. Ensure the properties you're accessing (like MainScreenTop) exist as settings in the project's properties.

Upvotes: 2

Yannick Mickler
Yannick Mickler

Reputation: 39

I think you should use setting variables: https://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx

Upvotes: 2

Related Questions