C#变量范围 - 问题 [英] C# Variable scope - problem

查看:100
本文介绍了C#变量范围 - 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,

为什么在这种情况下fn变量不可用?

 

当我从字符串中公开时,所有内容都会变成appart。

 

 

 

推荐答案

要将代码放入帖子中,请使用"插入代码块"图标  。

To put code into your post, please use the "Insert code block" icon .

通过这种方式,人们(像我一样)可以复制/粘贴您的代码进行试用!

That way people (like me) can copy/paste your code to try it out!

但是对于您的问题:您实际上并未说出确切的错误消息,是吗?确定VS是
实际抱怨变量不可用?

But to your question: You haven't actually said what the exact error message is, Are you sure that VS is actually complaining about the variable not being available?

因为我可以看到的一个问题是fn变量可能不会发生如果你的Documents集合是空的,就会发生这种情况。 

Because one issue I can see is that the fn variable is potentially not going to be initialised. This would happen if your Documents collection is empty. 

因此Visual Studio实际上可能会抱怨一个可能没有初始化的变量。

So Visual Studio may actually be complaining about a variable that may not be initialised.

要解决此问题,只需使用默认值初始化它。

To resolve that, simply initialise it with a default value.

string fn = "";


这篇关于C#变量范围 - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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