• <tfoot id='kXbod'></tfoot>
    1. <small id='kXbod'></small><noframes id='kXbod'>

      • <bdo id='kXbod'></bdo><ul id='kXbod'></ul>

        <i id='kXbod'><tr id='kXbod'><dt id='kXbod'><q id='kXbod'><span id='kXbod'><b id='kXbod'><form id='kXbod'><ins id='kXbod'></ins><ul id='kXbod'></ul><sub id='kXbod'></sub></form><legend id='kXbod'></legend><bdo id='kXbod'><pre id='kXbod'><center id='kXbod'></center></pre></bdo></b><th id='kXbod'></th></span></q></dt></tr></i><div id='kXbod'><tfoot id='kXbod'></tfoot><dl id='kXbod'><fieldset id='kXbod'></fieldset></dl></div>
        <legend id='kXbod'><style id='kXbod'><dir id='kXbod'><q id='kXbod'></q></dir></style></legend>

        无法将 ListBox.ObjectCollection 转换为(类型化)数组

        时间:2023-10-07

          1. <tfoot id='V2bpg'></tfoot>
            <i id='V2bpg'><tr id='V2bpg'><dt id='V2bpg'><q id='V2bpg'><span id='V2bpg'><b id='V2bpg'><form id='V2bpg'><ins id='V2bpg'></ins><ul id='V2bpg'></ul><sub id='V2bpg'></sub></form><legend id='V2bpg'></legend><bdo id='V2bpg'><pre id='V2bpg'><center id='V2bpg'></center></pre></bdo></b><th id='V2bpg'></th></span></q></dt></tr></i><div id='V2bpg'><tfoot id='V2bpg'></tfoot><dl id='V2bpg'><fieldset id='V2bpg'></fieldset></dl></div>

              <small id='V2bpg'></small><noframes id='V2bpg'>

                <bdo id='V2bpg'></bdo><ul id='V2bpg'></ul>

                  <tbody id='V2bpg'></tbody>
                  <legend id='V2bpg'><style id='V2bpg'><dir id='V2bpg'><q id='V2bpg'></q></dir></style></legend>
                • 本文介绍了无法将 ListBox.ObjectCollection 转换为(类型化)数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将项目转换为字符串数组或用于填充 ListBox.DataSource 的类型.该类型已覆盖 ToString(),但我似乎无法将其转换为 String[].

                  I want to convert the items to a String array or the type that I used to fill the ListBox.DataSource. The type has overridden ToString() but I can't seems to get it converted, not even to String[].

                  String[] a = (String[])ListBox1.Items;
                  Contacts[] b = (Contacts[])ListBox1.Items;
                  

                  推荐答案

                  string[] a = ListBox1.Items.Cast<string>().ToArray();
                  

                  当然,如果您打算对 a 做的只是对其进行迭代,则不必调用 ToArray().您可以直接使用 Cast 返回的 IEnumerable,例如:

                  Of course, if all you plan to do with a is iterate over it, you don't have to call ToArray(). You can directly use the IEnumerable<string> returned from Cast<string>(), e.g.:

                  foreach (var s in ListBox1.Items.Cast<string>()) {
                      do_something_with(s);
                  }
                  

                  或者,如果你有办法将字符串转换为联系人,你可以这样做:

                  Or, if you have some way to convert strings to Contacts, you can do something like this:

                  IEnumerable<Contacts> c = ListBox1.Items.Cast<string>().Select(s => StringToContact(s));
                  

                  这篇关于无法将 ListBox.ObjectCollection 转换为(类型化)数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <i id='B2Vl2'><tr id='B2Vl2'><dt id='B2Vl2'><q id='B2Vl2'><span id='B2Vl2'><b id='B2Vl2'><form id='B2Vl2'><ins id='B2Vl2'></ins><ul id='B2Vl2'></ul><sub id='B2Vl2'></sub></form><legend id='B2Vl2'></legend><bdo id='B2Vl2'><pre id='B2Vl2'><center id='B2Vl2'></center></pre></bdo></b><th id='B2Vl2'></th></span></q></dt></tr></i><div id='B2Vl2'><tfoot id='B2Vl2'></tfoot><dl id='B2Vl2'><fieldset id='B2Vl2'></fieldset></dl></div>
                • <tfoot id='B2Vl2'></tfoot>
                    <legend id='B2Vl2'><style id='B2Vl2'><dir id='B2Vl2'><q id='B2Vl2'></q></dir></style></legend>
                  1. <small id='B2Vl2'></small><noframes id='B2Vl2'>

                        <tbody id='B2Vl2'></tbody>

                          <bdo id='B2Vl2'></bdo><ul id='B2Vl2'></ul>