English 中文(简体)
如何对阵列设置错误检查?
原标题:How to setup error checking for arrays?
  • 时间:2011-09-15 06:32:20
  •  标签:
  • c#
  • arrays

我正在使用超声波包和 par子。

我对情况变化感到困惑,如果变化低于某一水平,我就获得未经处理的例外,因为我试图对其中的某一要素[][]加以约束。

我将如何确定错误检查,以确保这些阵列是否在那里 t下了不适当的期望?

Eg. 如果我使用下面的法典,而且没有1-23.1条,那么我就有一个例外,但html的改动如此。 它需要处理无效的非现存阵列要素

    //first line
    textBlock1.Text = node[0][0];
    textBlock2.Text = node[0][1];
    textBlock3.Text = node[0][2];

    //first line
    textBlock4.Text = node[1][0];
    textBlock5.Text = node[1][1];
    textBlock6.Text = node[1][2];

    //first line
    textBlock7.Text = node[2][0];
    textBlock8.Text = node[2][1];
    textBlock9.Text = node[2][2];

该法典规定:

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    var html = e.Result;

    var doc = new HtmlDocument();
    doc.LoadHtml(html);

    var list = doc.DocumentNode.Descendants("div").ToList();

    var node = doc.DocumentNode.Descendants("table")
         .FirstOrDefault(x => x.Id == "departures")
        .Element("tbody")
         .Elements("tr")
          .Select(tr => tr.Elements("td").Select(td => td.InnerText).ToArray())
          .ToArray();
最佳回答

你可以检查两个层面的时间长度,例如:

if (node.Length > 2)
{
   //first line
   if (node[2].Length > 0)
   {
      textBlock7.Text = node[2][0];
   }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签