51992

C# alternative to Visual Basic .NET namespace My

I'm a VB.NET programmer, but I'm new to C# and now I'm working with C# project which uses local resource files (.resx).

Using VB.NET I can access to variables in resource file via <strong>My</strong>.Resources.< LocalResourceFile >.< MyVariable > . But in C# I can't find any alternatives for <strong>My</strong> namespace, but I still can access to resource if I replace <strong>My</strong> namespace with < MyProjectNamespace >.

Maybe there are any other way to access my local resources?

Answer1:

If you absolutely must use the equivalent of the My namespace, there is actually such a thing in C#. It is the Microsoft.VisualBasic.Devices.MyServices namespace. To use that, you must add a reference to Microsoft.VisualBasic.dll and add using Microsoft.VisualBasic.Devices; to your code file. For this route, see here: http://msdn.microsoft.com/en-us/library/ms173136.aspx

I would not, however recommend doing that. Instead, to access resources, you simply use MyNamespace.Properties.Resources like this:

namespace SomeNamespace { ... var myFile = SomeNamespace.Properties.Resources.MyFile; ... }

Answer2:

It still works the same way, just don't put "My.Resources" in front of the name. So if you added a .resx file named "Resource1" and put a string named "Foo" in the resource then the variable name is "Resource1.Foo".

If you put code in non-default namespaces then you may have to prefix it with the default project namespace. Like "WindowsFormsApplication1.Resource1.Foo". If you are lost then just look at the auto-generated code. In the Solution Explorer window open the node next to the .resx file and double-click the Designer.cs file. Don't edit it.

Answer3:

You can do this which is virtually the equivalent:

Bitmap image = Properties.Resources.picture000;

Answer4:

There is no built-in My namespace, but you can reference Microsoft.VisualBasic.dll and have it.

Check out: http://msdn.microsoft.com/en-us/library/ms173136(v=vs.80).aspx

Recommend

  • output multidimensional array to grid style textbox
  • Expression of type 'Microsoft.TeamFoundation.Build.Workflow.Activities.BuildSettings'
  • Exception initializing Emgu.CV
  • Are there any advantages to using the VB.NET Like Operator vs a RegEx?
  • What is the difference between Google Developers Console project and a Google **Play** Developers Co
  • on slick 2.0, I find I can not store user defined field
  • Override FROM image's ENV in Dockerfile
  • Rewriting Amazon S3 static urls [closed]
  • Rails routing for has_and_belongs_to_many relationship
  • Azure Resource Template Deployment issues
  • Trying to get mvc resources to serve my static resources
  • Apply PivotItemHeader style to PivotItem in UWP
  • Which reference source does include Microsoft.VisualBasic?
  • How to add a resource file to Visual Studios so that it's visible in “Select Resource” dialog?
  • Query with in a loop getting slower and slower
  • Binding from within a ResourceDictionary in a Catel WPF UserControl
  • Android error - Failed to find style 'toolbarStyle' in current theme
  • Load image without autoscaling in Android
  • x-axis labels in coreplot not displayed
  • Why isn't Kubernetes service DNS working?
  • Locating unmatched delimiters in Clojurescript
  • Android: how to determine cold start
  • How do I create an image and save it for later to draw as texture in XNA?
  • What is the equivalent of Android permissions in iOS development? [duplicate]
  • jersey/tomcat Description The origin server did not find a current representation for the target res
  • how to change api_token column in token guard
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • Bash if statement with multiple conditions
  • UWP/C# - Issue with AQS and USB Devices
  • GAE: Way to get reference to an HttpSession from its ID?
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • What is the purpose of TaskExecutor in spring?
  • JBoss External Properties Files in Classpath
  • Atlas images wrong size on iPad iOS 9
  • Projection media query: browser support and workarounds?
  • WOWZA + RTMP + HTML5 Playback?
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS