本文整理汇总了C#中System.Last方法的典型用法代码示例。如果您正苦于以下问题:C# System.Last方法的具体用法?C# System.Last怎么用?C# System.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArraysShouldBeRoundtrippable
public void ArraysShouldBeRoundtrippable()
{
new TestScheduler().With(sched =>
{
string path;
var input = new[] {new UserObject {Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com"}, new UserObject {Bio = "zzz", Name = "sleepy", Blog = "http://example.com"}};
UserObject[] result;
using (Utility.WithEmptyDirectory(out path))
{
using (var fixture = CreateBlobCache(path))
{
fixture.InsertObject("key", input);
}
sched.Start();
using (var fixture = CreateBlobCache(path))
{
var action = fixture.GetObjectAsync<UserObject[]>("key");
sched.Start();
result = action.First();
}
}
Assert.Equal(input.First().Blog, result.First().Blog);
Assert.Equal(input.First().Bio, result.First().Bio);
Assert.Equal(input.First().Name, result.First().Name);
Assert.Equal(input.Last().Blog, result.Last().Blog);
Assert.Equal(input.Last().Bio, result.Last().Bio);
Assert.Equal(input.Last().Name, result.Last().Name);
});
}
示例2: CubeHash
static CubeHash()
{
var hashes = new[] {28, 32, 48, 64};
var rounds = new[] {1, 2, 4, 8, 16};
var blocksizes = new[] {1, 2, 4, 8, 16, 32, 64, 128};
var inits = new uint[rounds.Last() + 1,hashes.Last() + 1,blocksizes.Last() + 1][];
var zeroes = new byte[blocksizes.Last()];
foreach(int round in rounds)
{
foreach(int hashsize in hashes)
{
foreach(int blocksize in blocksizes)
{
CubeHash ch = new CubeHashCustom(HashLib.HashSize.HashSize256, round, blocksize);
ch.m_state[0] = (uint)hashsize;
ch.m_state[1] = (uint)blocksize;
ch.m_state[2] = (uint)round;
for(int i = 0; i < 10; i++)
ch.TransformBlock(zeroes, 0);
inits[round, hashsize, blocksize] = new uint[32];
Array.Copy(ch.m_state, inits[round, hashsize, blocksize], 32);
}
}
}
m_inits = inits;
}
示例3: ArraysShouldBeRoundtrippableUsingObjectFactory
public void ArraysShouldBeRoundtrippableUsingObjectFactory()
{
new TestScheduler().With(sched =>
{
string path;
var input = new[] {new UserModel(new UserObject()) {Age = 123, Name = "Old"}, new UserModel(new UserObject()) {Age = 123, Name = "Old"}};
UserModel[] result;
using (Utility.WithEmptyDirectory(out path))
{
using (var fixture = new TPersistentBlobCache(path))
{
fixture.InsertObject("key", input);
}
sched.Start();
using (var fixture = new TPersistentBlobCache(path))
{
var action = fixture.GetObjectAsync<UserModel[]>("key");
sched.Start();
result = action.First();
}
}
Assert.Equal(input.First().Age, result.First().Age);
Assert.Equal(input.First().Name, result.First().Name);
Assert.Equal(input.Last().Age, result.Last().Age);
Assert.Equal(input.Last().Name, result.Last().Name);
});
}
示例4: Main
public static void Main () {
var ints = new[] { 1, 2, 3, 4 };
Console.WriteLine(ints.Last());
Console.WriteLine(ints.Last((i) => i < 3));
// Test the non-IList path
Console.WriteLine(ints.Skip(1).Last());
Console.WriteLine(ints.Skip(1).Last((i) => i < 3));
}
示例5: PathEquals
public static void PathEquals(this Uri u, string pathAndQueryString)
{
var paths = (pathAndQueryString ?? "").Split(new[] { '?' }, 2);
string path = paths.First(), query = string.Empty;
if (paths.Length > 1)
query = paths.Last();
var expectedUri = new UriBuilder("http", "localhost", u.Port, path, "?" + query).Uri;
u.AbsolutePath.Should().Be(expectedUri.AbsolutePath);
u = new UriBuilder(u.Scheme, u.Host, u.Port, u.AbsolutePath, u.Query.Replace("pretty=true&", "").Replace("pretty=true", "")).Uri;
var queries = new[] { u.Query, expectedUri.Query };
if (queries.All(string.IsNullOrWhiteSpace)) return;
if (queries.Any(string.IsNullOrWhiteSpace))
{
queries.Last().Should().Be(queries.First());
return;
}
var clientKeyValues = u.Query.Substring(1).Split('&')
.Select(v => v.Split('='))
.Where(k => !string.IsNullOrWhiteSpace(k[0]))
.ToDictionary(k => k[0], v => v.Last());
var expectedKeyValues = expectedUri.Query.Substring(1).Split('&')
.Select(v => v.Split('='))
.Where(k => !string.IsNullOrWhiteSpace(k[0]))
.ToDictionary(k => k[0], v => v.Last());
clientKeyValues.Count.Should().Be(expectedKeyValues.Count);
clientKeyValues.Should().ContainKeys(expectedKeyValues.Keys.ToArray());
clientKeyValues.Should().Equal(expectedKeyValues);
}
示例6: Should_route_to_pared_down_process
public void Should_route_to_pared_down_process()
{
var messageABC = new SequentialProcess
{
StepAInfo = "Foo",
StepBInfo = "Bar",
StepCInfo = "Baz",
};
var destinations = new[]
{
"NServiceBus.MessageRouting.RoutingSlips.Samples.StepA",
"NServiceBus.MessageRouting.RoutingSlips.Samples.StepC",
"NServiceBus.MessageRouting.RoutingSlips.Samples.ResultHost",
};
Console.WriteLine("Sending message...");
var last = destinations.Last();
var events = _fixture.SendAndWait(
bus => bus.Route(messageABC, Guid.NewGuid(), destinations),
c => c.Endpoint != last,
TimeSpan.FromSeconds(60)).ToArray();
events.Count().ShouldEqual(3);
}
示例7: CalculateRibbon
static int CalculateRibbon(Package package)
{
IEnumerable<int> smallest = new[] { package.Length, package.Width, package.Height }.OrderBy(x => x).Take(2);
int ribbon = (smallest.First() * 2) + (smallest.Last() * 2) + (package.Length * package.Width * package.Height);
return ribbon;
}
示例8: DataChunk_WithTwoItems_SetsLastItem
public void DataChunk_WithTwoItems_SetsLastItem()
{
//Arrange
var input = new[] { "Johnson", "Controls" };
//Act
var actual = new DataChunk<string>(input, isEnd: true);
//Assert
Assert.AreEqual(input.Last(), actual.LastElement, "Failed to set last item of enumeration.");
}
示例9: OrderBy_DoesNotSort_WhenExpressionsIsNull
public void OrderBy_DoesNotSort_WhenExpressionsIsNull()
{
var data = new[]
{
new User { Name = "user2" },
new User { Name = "user3" },
new User { Name = "user1" },
};
var orderedQueryable = data.AsQueryable().OrderBy(null);
orderedQueryable.Count().ShouldEqual(3);
orderedQueryable.First().ShouldEqual(data.First());
orderedQueryable.Skip(1).First().ShouldEqual(data.Skip(1).First());
orderedQueryable.Last().ShouldEqual(data.Last());
}
示例10: OrderBy_SortsSimpleQueryable_Ascending
public void OrderBy_SortsSimpleQueryable_Ascending()
{
var data = new[]
{
new User { Name = "user2" },
new User { Name = "user3" },
new User { Name = "user1" },
};
var orderBy = new Dictionary<Expression<Func<User, object>>, OrderByDirection>
{
{ x => x.Name, OrderByDirection.Ascending },
};
var orderedQueryable = data.AsQueryable().OrderBy(orderBy);
orderedQueryable.Count().ShouldEqual(3);
orderedQueryable.First().ShouldEqual(data.Last());
orderedQueryable.Skip(1).First().ShouldEqual(data.First());
orderedQueryable.Last().ShouldEqual(data.Skip(1).First());
}
示例11: GetSameMappingFromTwoDifferentIndices
public void GetSameMappingFromTwoDifferentIndices()
{
var indices = new[]
{
ElasticsearchConfiguration.NewUniqueIndexName(),
ElasticsearchConfiguration.NewUniqueIndexName()
};
var x = this.Client.CreateIndex(indices.First(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());
x = this.Client.CreateIndex(indices.Last(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());
var response = this.Client.GetMapping<ElasticsearchProject>(i => i
.Index(string.Join(",", indices))
.Type("elasticsearchprojects")
);
response.Should().NotBeNull();
response.Mappings.Should().NotBeEmpty()
.And.HaveCount(2);
foreach (var indexMapping in response.Mappings)
{
var indexName = indexMapping.Key;
indices.Should().Contain(indexName);
var mappings = indexMapping.Value;
mappings.Should().NotBeEmpty().And.HaveCount(1);
foreach (var mapping in mappings)
{
mapping.TypeName.Should().Be("elasticsearchprojects");
TestElasticsearchProjectMapping(mapping.Mapping);
}
}
}
示例12: LastWorks
public void LastWorks()
{
var sut = new[] {1, 2, 3};
Assert.AreEqual(3, sut.Last());
var sut2 = new int[0];
Assert.AreEqual(0, sut2.Last());
try {
Assert.AreEqual(0, sut2.Last(true));
throw new Exception("This line should not be reached.");
}
catch (InvalidOperationException) {}
var sut3 = new[] {"1", "2", "3"};
Assert.AreEqual("3", sut3.Last());
var sut4 = new string[0];
Assert.Null(sut4.Last());
try {
Assert.Null(sut4.Last(true));
throw new Exception("This line should not be reached.");
}
catch (InvalidOperationException) {}
}
示例13: CourseViewHasAllStudents
public void CourseViewHasAllStudents()
{
var courseId = Guid.NewGuid();
var courses = new[]
{
new CourseModel { Id = Guid.NewGuid(), Name = "first name" },
new CourseModel { Id = courseId, Name = "second name" }
};
mockCourseRepository.Setup(r => r.FindAll()).Returns(courses);
var students = new[]
{
new StudentModel { Id = Guid.NewGuid(), FirstName = "first first name" },
new StudentModel { Id = Guid.NewGuid(), FirstName = "second first name" }
};
mockStudentRepository.Setup(r => r.FindAll()).Returns(students);
var result = controller.Course(courseId) as ViewResult;
var model = result.Model as CoursesTakenModel;
Assert.That(model.ToAssign.Count(), Is.EqualTo(2));
var names = model.ToAssign.Select(a => a.Name);
Assert.That(names, Contains.Item("first first name"));
Assert.That(names, Contains.Item("second first name"));
var ids = model.ToAssign.Select(a => a.Id);
Assert.That(ids, Contains.Item(students.First().Id));
Assert.That(ids, Contains.Item(students.Last().Id));
}
示例14: SubtypeHasFurtherSubtype
public void SubtypeHasFurtherSubtype()
{
encounterTypeAndAmount.Clear();
encounterTypeAndAmount["creature[challenge rating]"] = "creature amount";
requiresSubtype.Add("creature");
requiresSubtype.Add("other creature");
var subSubtypes = new[] { "wrong subtype", "subtype" };
mockCollectionSelector.Setup(s => s.SelectFrom(TableNameConstants.CreatureGroups, "other creature"))
.Returns(subSubtypes);
mockCollectionSelector.Setup(s => s.SelectFrom(TableNameConstants.CreatureGroups, "creature"))
.Returns(new[] { "wrong creature", "other creature" });
mockCollectionSelector.SetupSequence(s => s.SelectRandomFrom(subSubtypes)).Returns(subSubtypes.First()).Returns(subSubtypes.Last());
var tableName = string.Format(TableNameConstants.CREATURESubtypeChallengeRatings, "creature");
mockCollectionSelector.Setup(s => s.SelectFrom(tableName, "other creature")).Returns(new[] { "other challenge rating" });
tableName = string.Format(TableNameConstants.CREATURESubtypeChallengeRatings, "other creature");
mockCollectionSelector.Setup(s => s.SelectFrom(tableName, "subtype")).Returns(new[] { "challenge rating" });
mockRollSelector.Setup(s => s.SelectFrom(level, "challenge rating")).Returns("roll");
mockDice.Setup(d => d.Roll("roll")).Returns(600);
mockCollectionSelector.Setup(s => s.SelectFrom(tableName, "wrong subtype")).Returns(new[] { "wrong challenge rating" });
mockCollectionSelector.Setup(s => s.SelectFrom(tableName, "wrong creature")).Returns(new[] { "wrong challenge rating" });
mockRollSelector.Setup(s => s.SelectFrom(level, "wrong challenge rating")).Returns("wrong roll");
mockDice.Setup(d => d.Roll("wrong roll")).Returns(1337);
mockRollSelector.Setup(s => s.SelectFrom("creature amount", 9876)).Returns("creature effective roll");
mockDice.Setup(d => d.Roll("creature effective roll")).Returns(7654);
var encounter = encounterGenerator.Generate(environment, level, temperature, timeOfDay);
Assert.That(encounter, Is.Not.Null);
var creature = encounter.Creatures.Single();
Assert.That(creature.Name, Is.EqualTo("creature"));
Assert.That(creature.Description, Is.EqualTo("other creature (subtype)"));
Assert.That(creature.Quantity, Is.EqualTo(7654));
Assert.That(encounter.Characters, Is.Empty);
}
示例15: Dequeue_ShouldFetchJobs_FromMultipleQueues
public void Dequeue_ShouldFetchJobs_FromMultipleQueues()
{
string arrangeSql = string.Format(CultureInfo.InvariantCulture, @"
EXECUTE BLOCK (invocationData BLOB SUB_TYPE 1 SEGMENT SIZE 80 CHARACTER SET UNICODE_FSS = @invocationData,
arguments BLOB SUB_TYPE 1 SEGMENT SIZE 80 CHARACTER SET UNICODE_FSS = @arguments,
queue VARCHAR(20) CHARACTER SET UNICODE_FSS = @queue)
AS
DECLARE new_id int;
BEGIN
INSERT INTO ""{0}.JOB"" (invocationdata, arguments, createdat)
VALUES (:invocationData, :arguments, DATEADD(minute, -{1:N5}*60, current_timestamp))
RETURNING id INTO :new_id;
INSERT INTO ""{0}.JOBQUEUE"" (jobid, queue)
VALUES (:new_id, :queue);
SUSPEND;
END", _options.Prefix, _options.UtcOffset);
var queueNames = new[] { "default", "critical" };
UseConnection(connection =>
{
connection.Execute(
arrangeSql,
new[]
{
new { queue = queueNames.First(), invocationData = "", arguments = "" },
new { queue = queueNames.Last(), invocationData = "", arguments = "" }
});
var queue = CreateJobQueue(connection);
var queueFirst = (FirebirdFetchedJob)queue.Dequeue(
queueNames,
CreateTimingOutCancellationToken());
Assert.NotNull(queueFirst.JobId);
Assert.Contains(queueFirst.Queue, queueNames);
var queueLast = (FirebirdFetchedJob)queue.Dequeue(
queueNames,
CreateTimingOutCancellationToken());
Assert.NotNull(queueLast.JobId);
Assert.Contains(queueLast.Queue, queueNames);
});
}