本文整理汇总了C#中System.Collections.Generic.Count方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Count方法的具体用法?C# System.Collections.Generic.Count怎么用?C# System.Collections.Generic.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Count方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Do_Stuff
public void Can_Do_Stuff()
{
// Arrange - Set up what i`m going to work with
IEnumerable<int> numbers = new[] {0, 1, 2, 3, 4, 5};
// Act - Do the Stuff
var avg = numbers.Sum()/numbers.Count(n => n != 0);
// Assert - Validate it worked
Assert.AreEqual(avg, 3);
Assert.AreEqual(numbers.Sum(), 15);
Assert.IsTrue(numbers.Count() == 6);
Assert.IsTrue(numbers.Count(n => n != 0) == 5);
}
示例2: Hand
public void Hand()
{
var hand = new Hand();
IEnumerable<Dice> dices = new[] {new Dice(1, 16), new Dice(4, 8)};
IDiceRoll diceRoll = hand.Roll(dices);
Assert.AreEqual(diceRoll.Values.Count(), dices.Count());
Assert.IsTrue(diceRoll.Sum >= 5);
Assert.IsTrue(diceRoll.Sum <= 24);
}
示例3: GetSource
private IEnumerable<HTMLTag> GetSource()
{
IEnumerable<HTMLTag> source = new[] { this };
if (source.Count() == 1 &&
source.First().TypeEqualsIgnoreCase("html"))
{
source = source.First().ChildTags;
}
return source;
}
示例4: AddRange_WithCollection_AddsAllItemsToCollection
public void AddRange_WithCollection_AddsAllItemsToCollection()
{
// arrange
IEnumerable<int> numbers = new[] { 5, 4, 3 };
ICollection<int> items = new List<int>();
// act
items.AddRange(numbers);
// assert
Assert.AreEqual(3, numbers.Count());
}
示例5: ShapeSheet_Query_NonExistentSections
public void ShapeSheet_Query_NonExistentSections()
{
var page1 = this.GetNewPage();
var s1 = page1.DrawRectangle(0, 0, 2, 2);
var s2 = page1.DrawRectangle(2, 1, 3, 3);
var s3 = page1.DrawRectangle(3, 1, 4, 2);
var s4 = page1.DrawRectangle(4, -1, 5, 1);
var shapes = new[] {s1, s2, s3, s4};
var shapeids = shapes.Select(s => s.ID).ToList();
// First verify that none of the shapes have the controls section locally or otherwise
foreach (var s in shapes)
{
Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
}
// Try to retrieve the control cells rows for each shape, every shape should return zero rows
foreach (var s in shapes)
{
var r1 = VACONT.ControlCells.GetCells(s);
Assert.AreEqual(0,r1.Count);
}
// Try to retrieve the control cells rows for all shapes at once, every shape should return a collection of zero rows
var r2 = VACONT.ControlCells.GetCells(page1, shapeids);
Assert.AreEqual(shapes.Count(),r2.Count);
for (int i = 0; i < shapes.Count();i++)
{
Assert.AreEqual(0,r2[i].Count);
}
// Add a Controls row to shape2
var cc = new VACONT.ControlCells();
VACONT.ControlHelper.Add(s2, cc);
// Now verify that none of the shapes *except s2* have the controls section locally or otherwise
foreach (var s in shapes)
{
if (s != s2)
{
Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
}
else
{
Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
}
}
// Try to retrieve the control cells rows for each shape, every shape should return zero rows *except for s2*
foreach (var s in shapes)
{
if (s != s2)
{
var r1 = VACONT.ControlCells.GetCells(s);
Assert.AreEqual(0, r1.Count);
}
else
{
var r1 = VACONT.ControlCells.GetCells(s);
Assert.AreEqual(1, r1.Count);
}
}
// Try to retrieve the control cells rows for all shapes at once, every shape *except s2* should return a collection of zero rows
var r3 = VACONT.ControlCells.GetCells(page1, shapeids);
Assert.AreEqual(shapes.Count(), r3.Count);
for (int i = 0; i < shapes.Count(); i++)
{
if (shapes[i] != s2)
{
Assert.AreEqual(0, r3[i].Count);
}
else
{
Assert.AreEqual(1, r3[i].Count);
}
}
page1.Delete(0);
}
示例6: CheckIsRejected_ExecuteCode
private void CheckIsRejected_ExecuteCode(object sender, ConditionalEventArgs e)
{
if (_externalState == null)
{
e.Result = false;
return;
}
var codes = new[]
{
BillDemandExternalStatus.Rejected, BillDemandExternalStatus.RejectedInBOSS,
BillDemandExternalStatus.Destroyed
};
e.Result = codes.Count(p => p.Code == _externalState.Status.Code) > 0;
if (e.Result)
Comment = GetExernalStatusComment();
}
示例7: TestNotificationProcessingMultipleDBs
public void TestNotificationProcessingMultipleDBs()
{
var store1 = GetTestStore();
var store2 = GetTestStore();
var store3 = GetTestStore();
const int numberToTest = 100;
var stores = new [] {store1, store2, store3};
StoreTestNotifications(numberToTest, stores);
var logStub = MockRepository.GenerateStub<log4net.ILog>();
var storeStub = MockRepository.GenerateStub<IDocumentStore>();
var processor = new NotificationProcessor(
new EmailNotificationDispatcher( logStub,new TestEmailSender{Store = store1}),
new ToastDispatcher(storeStub, logStub),
stores,
new SmsDispatcher(logStub,new TestSmsSender()),
logStub,
100
);
var numberProcessed = processor.Process();
Assert.AreEqual(numberProcessed, numberToTest*stores.Count());
using (var session = store1.OpenSession())
{
var overdueNotifications = session.Query<Notification>().Where(n => !n.Sent && n.SendDate < DateTime.UtcNow).ToArray();
Assert.AreEqual(0, overdueNotifications.Count());
}
}
示例8: should_get_element_element_using_count
public void should_get_element_element_using_count()
{
var sequence = new[] { 1, 2, 3, 4, 5 };
int totalNumber = sequence.Count();
int numberOfEvenNumbers = sequence.Count(item => item % 2 == 0);
// please update variable value to fix the test.
const int expectedTotalNumber = 0;
const int expectedNumberOfEvenNumbers = 0;
Assert.Equal(expectedTotalNumber, totalNumber);
Assert.Equal(expectedNumberOfEvenNumbers, numberOfEvenNumbers);
}
示例9: FilterHelper_FilterByName_assign_name_filter
public void FilterHelper_FilterByName_assign_name_filter()
{
//Arrange
sut.FilterByName(viewData, "asd");
//Act
var nameFilter = "asd";
var expectedConferences = new[]
{
new Conference
{
Name = "asd"
}
};
//Assert
Assert.AreEqual(expectedConferences.Count(), sut.Conferences.Count());
Assert.AreEqual(expectedConferences[0].Name, sut.Conferences.ToList()[0].Name);
Assert.AreEqual(nameFilter, viewData["NameFilter"]);
}
示例10: GetNumberOfCompletedTredgesOnTopLayer
private int GetNumberOfCompletedTredgesOnTopLayer(CubeConfiguration<FaceColour> configuration)
{
var allFaces = new[] { FaceType.Front, FaceType.Left, FaceType.Back, FaceType.Right };
return allFaces.Count(f => Utilities.IsInnerEdgeComplete(f, FaceType.Upper, configuration));
}