问题描述
你好, 为什么在这种情况下fn变量不可用? 当我从字符串中公开时,所有内容都会变成appart。 通过这种方式,人们(像我一样)可以复制/粘贴您的代码进行试用! 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 isactually 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. 这篇关于C#变量范围 - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
推荐答案
实际抱怨变量不可用?string fn = "";