本文整理汇总了C#中System.Collections.Generic.First方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.First方法的具体用法?C# System.Collections.Generic.First怎么用?C# System.Collections.Generic.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.First方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSource
private IEnumerable<HTMLTag> GetSource()
{
IEnumerable<HTMLTag> source = new[] { this };
if (source.Count() == 1 &&
source.First().TypeEqualsIgnoreCase("html"))
{
source = source.First().ChildTags;
}
return source;
}
示例2: Accumulate_WithTwoEnumerations_AccumulatesOneIntoTheOther
public void Accumulate_WithTwoEnumerations_AccumulatesOneIntoTheOther()
{
// arrange
var containers = new[] { new KeyValuePair<int, List<string>>(0, new List<string>()), new KeyValuePair<int, List<string>>(1, new List<string>()), new KeyValuePair<int, List<string>>(2, new List<string>()), new KeyValuePair<int, List<string>>(3, new List<string>()) };
var items = new[] {new KeyValuePair<int, string>(1, "A"), new KeyValuePair<int, string>(1, "B"), new KeyValuePair<int, string>(3, "C")};
// act
containers.Accumulate(items, container => container.Key, item => item.Key, (container, item) => container.Value.Add(item.Value));
// assert
Assert.AreEqual(0, containers.First().Value.Count);
var secondContainer = containers.ElementAt(1);
Assert.AreEqual(2, secondContainer.Value.Count);
Assert.AreEqual("A", secondContainer.Value[0]);
Assert.AreEqual("B", secondContainer.Value[1]);
Assert.AreEqual(0, containers.ElementAt(2).Value.Count);
var fourthContainer = containers.ElementAt(3);
Assert.AreEqual(1, fourthContainer.Value.Count);
Assert.AreEqual("C", fourthContainer.Value[0]);
}
示例3: GetGeometryColumnValue_returns_a_DbGeography
private void GetGeometryColumnValue_returns_a_DbGeography(bool useSpatialReader)
{
var sourceEnumerable = new[] { new object[] { DbGeometry.FromText("POINT (90 50)") } };
var reader = MockHelper.CreateDbDataReader(sourceEnumerable);
var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0));
var shaperMock = new Mock<Shaper<object>>(
reader,
/*context*/ null,
/*workspace*/ null,
MergeOption.AppendOnly,
/*stateCount*/ 1,
coordinatorFactory,
/*readerOwned*/ false,
/*useSpatialReader*/ useSpatialReader,
/*shouldReleaseConnection*/ true)
{
CallBase = true
};
var spatialDataReaderMock = new Mock<DbSpatialDataReader>(MockBehavior.Strict);
if (useSpatialReader)
{
spatialDataReaderMock.Setup(m => m.GetGeometry(0)).Returns((DbGeometry)sourceEnumerable.First()[0]);
}
shaperMock.Protected().Setup<DbSpatialDataReader>("CreateSpatialDataReader").Returns(spatialDataReaderMock.Object);
reader.Read();
Assert.Equal(sourceEnumerable.First()[0], shaperMock.Object.GetGeometryColumnValue(0));
if (useSpatialReader)
{
spatialDataReaderMock.Verify(m => m.GetGeometry(0), Times.Once());
}
}
示例4: ProgramClientDataTable
public void GivenProgramWithServiceTypes_AndServiceTypesCanBeDuplicated_WhenExecuteDataSelector_ThenServiceTypeListMatches()
{
ProgramClientDataTable target = new ProgramClientDataTable(MockRequest);
string[] expected = new[] { "Apple", "Orange", "Banana" };
Program program = new Program
{
ServiceOfferings = expected.Select(name => new ServiceOffering { IsActive = true, ServiceType = new ServiceType { Name = name } }).ToList()
};
program.ServiceOfferings.Add(new ServiceOffering { IsActive = true, ServiceType = new ServiceType { Name = expected.First() } });
dynamic actual = target.DataSelector.Compile().Invoke(program);
CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.ServiceTypes).ToList());
}
示例5: when_using_a_visitor
public void when_using_a_visitor()
{
//setup
var controller = new PropertyBagVersionController<FlatPropertyBag>(TestHelper.CreateWithNonDefaultProperties<FlatPropertyBag>(),
_testHelper.MakeConfiguredCloneFactoryFor<FlatPropertyBag>(),
_testHelper.EmptyChangeSet(),
_testHelper.MakeConfiguredVisitorFactory(),
_testHelper.MakeConfiguredProxyFactory());
var fakeChildren = new[] {A.Fake<IVersionControlNode>(), A.Fake<IVersionControlNode>()};
var fakeVisitor = A.Fake<IVersionControlTreeVisitor>();
controller.Children.AddRange(fakeChildren);
//act
controller.Accept(fakeVisitor);
//assert
A.CallTo(() => fakeChildren.First().RecursiveAccept(fakeVisitor)).MustHaveHappened();
A.CallTo(() => fakeChildren.Last().RecursiveAccept(fakeVisitor)).MustHaveHappened();
A.CallTo(() => fakeVisitor.OnEntry(controller)).MustHaveHappened();
}
示例6: should_get_first_element_using_first
public void should_get_first_element_using_first()
{
var sequence = new[] { 1, 2, 3, 4, 5 };
int firstElement = sequence.First();
int firstEvenNumber = sequence.First(item => item % 2 == 0);
// please update variable values for the following 2 lines to fix the test.
const int expectedFirstElement = 0;
const int expectedFirstEvenNumber = 0;
Assert.Equal(expectedFirstElement, firstElement);
Assert.Equal(expectedFirstEvenNumber, firstEvenNumber);
}