Unable to use Environment.GetResourceString static method

喜你入骨 提交于 2019-12-14 03:53:01

问题


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Environment.GetResourceString("test"); //compile-time error
        }
    }
}

The error is: 'System.Environment' does not contain a definition for 'GetResourceString'.

EDIT: OP has stated that he's using the Compact Framework, v3.5.

I dont get the picture, what's wrong with my code? Thanks!


回答1:


Environment.GetResourceString appears to be present, according to MSDN, only in version 2.0 of the Compact Framework. If the article is to be believed, it's never existed in the standard framework.

What are you trying to do? If it's localization you're after, you may want ResourceManager.GetString.

System.Resources.ResourceManager myManager = new 
   System.Resources.ResourceManager("ResourceNamespace.myResources", 
   myAssembly);

// Retrieves String and Image resources.
string myString = myManager.GetString("StringResource");



回答2:


Environment.GetResourceString is not public

internal static string GetResourceString(string key);

See Michael Petrottas answer for how to access resources or have a look at the samples here http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.aspx



来源:https://stackoverflow.com/questions/1794084/unable-to-use-environment-getresourcestring-static-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!