Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# listbox.item是对象还是字符串?C_C#_String_Object_Listbox - Fatal编程技术网

C# listbox.item是对象还是字符串?C

C# listbox.item是对象还是字符串?C,c#,string,object,listbox,C#,String,Object,Listbox,在今天的考试中收到以下问题,我不知道: listbox.item是字符串还是对象 有人能帮我清理一下吗?这是一个物体 读了这篇文章,你就会有了新的想法, 这是一个目标 也可以使用列表来查找字符串 private void FindMyString(string searchString) { // Ensure we have a proper string to search for. if (searchString != string.Empty) {

在今天的考试中收到以下问题,我不知道:

listbox.item是字符串还是对象

有人能帮我清理一下吗?

这是一个物体

读了这篇文章,你就会有了新的想法, 这是一个目标

也可以使用列表来查找字符串

    private void FindMyString(string searchString)
{
   // Ensure we have a proper string to search for. 
   if (searchString != string.Empty)
   {
      // Find the item in the list and store the index to the item. 
      int index = listBox1.FindString(searchString);
      // Determine if a valid index is returned. Select the item if it is valid. 
      if (index != -1)
         listBox1.SetSelected(index,true);
      else
         MessageBox.Show("The search string did not match any items in the ListBox");
   }
}
试试这个

 if (listBox1.DataSource == null)
        {
            // ----- items are string
        }
        else
        {
            //----items are object
        }

看医生。他们为此而做。你确定要检查数据源是否为空吗?@nilesh先生。若在列表框中添加了项,则数据源将为空,若将数据源分配给列表框,则数据源将不为空