如果我有一阵,,我想迅速检查一下,这些阵列中是否有一定价值,是否有这样做的方法?
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
如果我有一阵,,我想迅速检查一下,这些阵列中是否有一定价值,是否有这样做的方法?
如果对阵列进行分类,那么最快的是:
Array.BinarySearch(myArray, value) >= 0;
如果对阵列进行了搜查,很少加以修改,那么你可能认为,在修改后(使用<代码>Array.Sort<>/code>)对阵列进行分类并使用上述编码是值得的。 否则,采用你选择的办法:
Array.IndexOf(myArray, value) >= 0; //.Net 1
Array.Exists(array, delegate(int x) { return x == value; }); //.Net 2
myArray.Contains(value); //.Net 3
< 编码>IndexOf对未安装阵列的最好性能。 第二种选择是使用权势代表,第三项要求设定标语。
例如,如果你想要检查一下贵国的阵列是否包含第0号:
if (your_int_array.Contains(0))
{
//Code
}
千分之四 方法就是您的朋友。
您可使用IndexOf。 方法:
int[] array = new int[] { 1, 2, 3 };
bool isArrayContains17 = Array.IndexOf(array, 17) > -1;
var myArray = new [] { 1, 2};
if myArray.Contains(1)
{
do something
}
页: 1
祝福
丹麦
履行这一职能:
public static bool FindValueFromArray(object[] Values,object valueToSearch){
bool retVal = false;
Array myArray = (Array)Values;
int found = Array.BinarySearch(myArray, valueToSearch);
if (found != -1){
retVal = true;
}
return retVal;
}
希望这一帮助。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
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. ...
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 ...
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 ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
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, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
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. ...