我是 C# 新手,无法理解变量的范围。我在课程开始时声明了一个数组:
namespace TextProcessing
{
public static class Program
{
private static string[] ForewordArray;
Run Code Online (Sandbox Code Playgroud)
然后在 Main 中,我初始化并填充数组:
public static void Main(string[] args)
{
try
{
try
{
//snip - XML source is opened - snip
foreword = XMLnav.SelectSingleNode("//iso:foreword", NSmgr);
forewordText = foreword.InnerXml;
ForewordTextP = (forewordText.Length - forewordText.Replace("<p", string.Empty).Length) / 2 + 1;
CurrFPos = 1;
LastFPos = 1;
string[] ForewordArray = new string[ForewordTextP];
for (var z = 0; z <= ForewordTextP - 1; z++)
{
LastFPos = CurrFPos;
if …Run Code Online (Sandbox Code Playgroud) c# ×1