本文整理汇总了C#中System.Linq.Count方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Count方法的具体用法?C# System.Linq.Count怎么用?C# System.Linq.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.Count方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLogGroupsTest
public void GetLogGroupsTest()
{
var files = new[]
{
"C:\\Crawling.log.20140905.135957.txt",
"D:\\Crawling.log.20140905.txt",
"log.20140905.135957.txt",
"E:\\assaasd\\log.20140905.txt",
"readme.12324.txt",
"Search.log.20140905.135957.txt",
"Search.log.20140905.txt",
"WebDAV.log.20140905.135957.txt",
"WebDAV.log.20140905.txt"
};
var results = InstanceHelper.GetLogGroups(files).OrderBy(x => x).Select(x => x.ToLower()).ToArray();
var expected = new[]
{
"crawling.log", "log", "search.log", "webdav.log"
}.OrderBy(x => x).ToArray();
Assert.AreEqual(results.Count(), expected.Count());
for (int i = 0; i < expected.Count(); ++i)
{
Assert.AreEqual(expected[i], results[i]);
}
}
示例2: Prepend_adds_item_to_beginning_of_sequence
public void Prepend_adds_item_to_beginning_of_sequence()
{
var result = new[] { 2, 3 }.Prepend(1);
Assert.Equal(3, result.Count());
Assert.Equal(1, result.First());
Assert.Equal(3, result.Last());
}
示例3: Append_adds_item_to_end_of_sequence
public void Append_adds_item_to_end_of_sequence()
{
var result = new[] { 1, 2 }.Append(3);
Assert.Equal(3, result.Count());
Assert.Equal(1, result.First());
Assert.Equal(3, result.Last());
}
示例4: GetOrCreateWorks
public void GetOrCreateWorks()
{
GivenAUniverseCalled("B");
var names = new[] { "A", "a", "B", "C" };
var universes = MyMainDals.Universes.GetOrCreate(names);
Assert.Equal(names.Count(), universes.Count);
Assert.Equal(insertedUniverseId, universes[2].Id);
}
示例5: Execute
public void Execute()
{
var people = new[]
{
new Person {Name = "gsf_zero1"},
new Person {Name = "gsf_zero2"},
new Person {Name = "gsf_zero3"},
new Person {Name = "gsf_zero4"}
};
//
// Count拡張メソッドは、シーケンスの要素数を取得するメソッドである。
//
// Count拡張メソッドには、predicateを指定できるオーバーロードが存在し
// それを利用すると、特定の条件に一致するデータのみの件数を求める事が出来る。
//
// 尚、非常に多くの件数を返す可能性がある場合は、Countの代わりにLongCount拡張メソッドを
// 使用する。使い方は、Count拡張メソッドと同じ。
//
// predicate無しで実行.
//
Output.WriteLine("COUNT = {0}", people.Count());
//
// predicate有りで実行.
//
Output.WriteLine("COUNT = {0}", people.Count(person => int.Parse(person.Name.Last().ToString())%2 == 0));
//
// predicate無しで実行.(LongCount)
//
Output.WriteLine("COUNT = {0}", people.LongCount());
//
// predicate有りで実行.(LongCount)
//
Output.WriteLine("COUNT = {0}", people.LongCount(person => int.Parse(person.Name.Last().ToString())%2 == 0));
}
示例6: ShouldLogAnActivityForEachUserInvolvedInABuild
public void ShouldLogAnActivityForEachUserInvolvedInABuild()
{
Modification[] modifications = new[]
{
new Modification() {UserName = "fsinatra"},
new Modification() {UserName = "hsimpson"},
new Modification() {UserName = "morphius"},
};
_mockIntegrationResult.SetupGet(x => x.Succeeded).Returns(true);
_mockIntegrationResult.SetupGet(x => x.Modifications).Returns(modifications);
_task.Run(_mockIntegrationResult.Object);
_mockActivityService
.Verify(x => x.LogDeveloperActivities(It.IsAny<LogDeveloperActivityRequest>()),
Times.Exactly(modifications.Count()));
}
示例7: CheckCell
public static bool CheckCell(bool[,] arr, int i, int j)
{
int nextI = i == (x - 1) ? 0 : i + 1;
int prevI = i == 0 ? x - 1 : i - 1;
int nextJ = j == (y - 1) ? 0 : j + 1;
int prevJ = j == 0 ? y - 1 : j - 1;
bool[] neighbours = new[]{
arr[prevI, prevJ], arr[i, prevJ], arr[nextI, prevJ],
arr[prevI, j], arr[nextI, j], arr[prevI, nextJ],
arr[i, nextJ], arr[nextI, nextJ]
};
int val = neighbours.Count(c => c);
if (arr[i, j])
return (val >= 2 && val <= 3) ? true : false;
else
return (val == 3) ? true : false;
}
示例8: TryParseBoolArray
public void TryParseBoolArray()
{
const string strTrue = "true";
const string strTrueBit = "1";
const string strFalse = "false";
const string strFalseBit = "0";
const string strInvalid = "a";
var trueValues = new[] { strTrue, strTrueBit };
var falseValues = new[] { strFalse, strFalseBit };
var mixedValues = new[] { strTrue, strTrueBit, strFalse, strFalseBit, strInvalid };
var noneValues = new[] { strInvalid };
#region full method, without default, dont return defult false conversion
var trueConversions = string.Join(",", trueValues).TryParseBoolArray(null, false);
Assert.IsNotNull(trueConversions, "Error converting string to bool array");
Assert.IsTrue(trueConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(trueConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(trueConversions.Count() == trueValues.Count(), "Error converting string to bool array");
var falseConversions = string.Join(",", falseValues).TryParseBoolArray(null, false);
Assert.IsNotNull(falseConversions, "Error converting string to bool array");
Assert.IsTrue(falseConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(falseConversions.Any(a => a), "Error converting string to bool array");
Assert.IsTrue(falseConversions.Count() == falseValues.Count(), "Error converting string to bool array");
var mixedConversions = string.Join(",", mixedValues).TryParseBoolArray(null, false);
Assert.IsNotNull(mixedConversions, "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Any(a => a) && mixedConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Count() == (mixedValues.Count() - 1), "Error converting string to bool array");
var noneConversions = string.Join(",", noneValues).TryParseBoolArray(null, false);
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
Assert.IsFalse(noneConversions.Any(), "Error converting string to bool array");
#endregion
#region full method, with default, dont return defult false conversion
noneConversions = string.Join(",", noneValues).TryParseBoolArray(new []{true}, false);
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
Assert.IsTrue(noneConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(noneConversions.Any(a=> !a), "Error converting string to bool array");
#endregion
#region full method, without default, return defult false conversion
noneConversions = string.Join(",", noneValues).TryParseBoolArray(null, true);
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
Assert.IsTrue(noneConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(noneConversions.Any(a => a), "Error converting string to bool array");
#endregion
#region partial method, without default
trueConversions = string.Join(",", trueValues).TryParseBoolArray(null);
Assert.IsNotNull(trueConversions, "Error converting string to bool array");
Assert.IsTrue(trueConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(trueConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(trueConversions.Count() == trueValues.Count(), "Error converting string to bool array");
falseConversions = string.Join(",", falseValues).TryParseBoolArray(null);
Assert.IsNotNull(falseConversions, "Error converting string to bool array");
Assert.IsTrue(falseConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(falseConversions.Any(a => a), "Error converting string to bool array");
Assert.IsTrue(falseConversions.Count() == falseValues.Count(), "Error converting string to bool array");
mixedConversions = string.Join(",", mixedValues).TryParseBoolArray(null);
Assert.IsNotNull(mixedConversions, "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Any(a => a) && mixedConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Count() == (mixedValues.Count() - 1), "Error converting string to bool array");
noneConversions = string.Join(",", noneValues).TryParseBoolArray(null);
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
Assert.IsFalse(noneConversions.Any(), "Error converting string to bool array");
#endregion
#region partial method, with default
noneConversions = string.Join(",", noneValues).TryParseBoolArray(new[] { true });
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
Assert.IsTrue(noneConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(noneConversions.Any(a => !a), "Error converting string to bool array");
#endregion
#region simple method
trueConversions = string.Join(",", trueValues).TryParseBoolArray();
Assert.IsNotNull(trueConversions, "Error converting string to bool array");
Assert.IsTrue(trueConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(trueConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(trueConversions.Count() == trueValues.Count(), "Error converting string to bool array");
falseConversions = string.Join(",", falseValues).TryParseBoolArray();
Assert.IsNotNull(falseConversions, "Error converting string to bool array");
Assert.IsTrue(falseConversions.Any(), "Error converting string to bool array");
Assert.IsFalse(falseConversions.Any(a => a), "Error converting string to bool array");
Assert.IsTrue(falseConversions.Count() == falseValues.Count(), "Error converting string to bool array");
mixedConversions = string.Join(",", mixedValues).TryParseBoolArray();
Assert.IsNotNull(mixedConversions, "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Any(a => a) && mixedConversions.Any(a => !a), "Error converting string to bool array");
Assert.IsTrue(mixedConversions.Count() == (mixedValues.Count() - 1), "Error converting string to bool array");
noneConversions = string.Join(",", noneValues).TryParseBoolArray();
Assert.IsNotNull(noneConversions, "Error converting string to bool array");
//.........这里部分代码省略.........