我认为环境变量但我不会看到他 [英] I Adit A Environment Variable But I Dont See Him

查看:85
本文介绍了我认为环境变量但我不会看到他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为环境变量,但我没有看到他



i在mycomputer-> EnvironmentVariable->中查看

whayyyyyyyy ?????



这是要添加的代码:



string value =c:/init.e;



if(Environment.GetEnvironmentVariable(init)== null)

{

System.Environment.SetEnvironmentVariable(init,value);

}

i adit a Environment Variable but i dont see him

i checked in mycomputer->EnvironmentVariable->in the list there
whayyyyyyyy?????

this is the code to add :

string value="c:/init.e";

if (Environment.GetEnvironmentVariable("init") == null)
{
System.Environment.SetEnvironmentVariable("init", value);
}

推荐答案

什么都不应该返回布尔值。所有方法 SetEnviromentVariable 都是无效的,并且所有方法 GetEnvironmentVariable 都返回字符串值,如果这些变量的值为: http://msdn.microsoft.com/en-us/library/ system.environment%28v = vs.110%29.aspx [ ^ ]。



你的我看不到他的问题只是简单地说没有任何意义。



顺便说一句,没有任何人100%确信你确实设置了你的环境变量。首先,如果已找到此变量,则代码不会更改其值。此外,此代码将抛出异常是您的应用程序未获得足够的权限。谁知道,也许你在堆栈的上层堆栈框架上处理异常,所以异常的传播被阻止,所以你可能错过了它(这是许多初学者的常见错误)。



-SA
Nothing is supposed to return Boolean value. All the methods SetEnviromentVariable are void, and all the methods GetEnvironmentVariable return string values, the values if those variables: http://msdn.microsoft.com/en-us/library/system.environment%28v=vs.110%29.aspx[^].

Your "I don't see him" question simply makes no sense.

By the way, nothing 100% convinced me that you actually set your environment variable. First, if this variable is already found, your code won't change its value. Also, this code will throw exception is your application is not given sufficient permissions. Who knows, maybe you handle exceptions somewhere on upper stack frames of your stack, so the propagation of the exception is blocked, so you might have missed it (this is a usual mistake of many beginners).

—SA


您没有看到环境变量,因为它仅在您的应用程序正在执行的过程中设置。它不会全局设置该值,因此它会出现在所有进程中。
You don't see the environment variable because it's only set in the process that your app is executing in. It does NOT set that value globally so it appears in all processes.


这篇关于我认为环境变量但我不会看到他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆