C# 什么';这是申报托收的正确方式<;布尔>;对象和数据类型不同?
使用不同数据类型的集合对象的正确方法是什么 我发现C# 什么';这是申报托收的正确方式<;布尔>;对象和数据类型不同?,c#,.net,C#,.net,使用不同数据类型的集合对象的正确方法是什么 我发现类型或命名空间集合找不到错误。还发现成员变量\u isFormData同时是bool、int和string-/ 看到这个例子,在接受的答案下,在 private Collection_isFormData=new Collection()//布尔。。。 _Add(String.IsNullOrEmpty(contentDisposition.FileName))//一串 for(int index=0;index
类型或命名空间集合找不到
错误。还发现成员变量\u isFormData
同时是bool、int和string-/
看到这个例子,在接受的答案下,在
private Collection_isFormData=new Collection()//布尔。。。
_Add(String.IsNullOrEmpty(contentDisposition.FileName))//一串
for(int index=0;index
您需要使用System.Collections.ObjectModel创建一个要在类中正确引用的类型的代码>行
该类型仅为布尔值的集合:
String.IsNullOrEmpty(contentDisposition.FileName)
测试contentDisposition.FileName
是否为null
或”
,如果是,则返回true;否则就错了
isFormData[index]
返回元素索引处集合中的bool值。下面是一个示例。注意“使用System.Collections.ObjectModel”
使用系统;
使用系统集合;
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
公共课程
{
公共静态void Main(字符串[]args)
{
IList testCollection=新集合();
testCollection.Add(false);
testCollection.Add(true);
FillCollection(testCollection);
for(int index=0;index
在System.Collections.Generic
命名空间中没有集合
类型,您想要什么类型的集合<代码>列表
也许?它从来不是字符串
或int
String.IsNullOrEmpty
返回bool
,您可以使用int
索引集合,以在\u isFormData[index]
中提取bool
值。你可能在使用System.Collections.ObjectModel时遗漏了一个@BenRobinson?@juharr:啊!现在一切都有意义了。起初它让人困惑,当我使用“Collection”时,VisualStudio中的对象浏览器并没有返回任何结果。它现在可以工作了。实际上它只是使用System.Collections.ObjectModel
。啊!现在一切都有意义了。起初很混乱,当我使用“Collection”关键字搜索时,VisualStudio中的对象浏览器并没有返回任何命中率。现在可以了。现在又等了5分钟让StackOverflow让我接受答案。
isFormData[index]
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Program
{
public static void Main (String[] args)
{
IList<Boolean> testCollection = new Collection<Boolean>();
testCollection.Add(false);
testCollection.Add(true);
FillCollection(testCollection);
for (int index = 0; index < testCollection.Count; index++)
{
if (testCollection[index])
{
Console.WriteLine("testCollection[{0}] is true", index);
}
else
{
Console.WriteLine("testCollection[{0}] is false", index);
}
}
}
public static void FillCollection (IList<Boolean> collection)
{
Random random = new Random();
for (int i = 0; i < 500; i++)
{
Boolean item = Convert.ToBoolean(random.Next(0, 2));
collection.Add(item);
}
}
}