本文整理汇总了C#中List.Take方法的典型用法代码示例。如果您正苦于以下问题:C# List.Take方法的具体用法?C# List.Take怎么用?C# List.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
// GET: Home/Index
public async Task<ActionResult> Index()
{
// Get lift offers with min. 1 seat available, order by descending - most recent to oldest
var offersAll = await db.LiftOffers.OrderByDescending(
o => o.LiftOfferID).Where(o => o.SeatsAvailable > 0).ToListAsync();
// Create list with not expired offers to display in a view
var offersNotExpired = new List<LiftOffer>();
foreach (var off in offersAll)
{
// Check if EndDate is older then current date. If date null then set default - 01/01/0001
int result = DateTime.Compare(off.EndDate.GetValueOrDefault(), DateTime.Today);
// If EndDate greater or null, add offer to list of not expired offers
if ((result >= 0) || (off.EndDate == null))
{
offersNotExpired.Add(off);
}
}
var users = new List<User>();
foreach (LiftOffer off in offersNotExpired.Take(3))
{
User usr = db.Users.Find(off.UserID);
users.Add(usr);
}
ViewBag.Users = users.ToList();
// Display only 3 most recent offers
return View(offersNotExpired.Take(3).ToList());
}
示例2: SocketReadLine
partial void SocketReadLine(ref string response)
{
var encoding = new Renci.SshNet.Common.ASCIIEncoding();
var line = new StringBuilder();
// Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
var buffer = new List<byte>();
var data = new byte[1];
do
{
var received = this._socket.Receive(data);
// If zero bytes received then exit
if (received == 0)
break;
buffer.Add(data[0]);
}
while (!(buffer.Count > 1 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));
// Return an empty version string if the buffer consists of a 0x00 character.
if (buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
else
response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
}
示例3: Gpu
public Gpu(IMmu mmu, params Color[] palette)
{
_mmu = mmu;
_defaultPalette = new List<Color>()
{
Colors.GhostWhite,
Colors.LightSlateGray,
Colors.DarkSlateBlue,
Colors.Black
};
for (int i = 0; i < 4; i++)
{
if (i < palette.Length)
{
_defaultPalette[i] = palette[i];
}
}
_bgPalette = _defaultPalette.Take(4).ToList();
_spritePalette = _defaultPalette.Take(4).ToList();
Reset();
}
示例4: GetEventDetails
private void GetEventDetails()
{
try
{
// EventListingViewModel _eventListingViewModel = new EventListingViewModel();
// List<EventListingModel> _eventListingModel = new List<EventListingModel>();
// rcontent.DataSource = _eventListingModel.Take(4);
// rcontent.DataBind();
// rQuickBook.DataSource = _eventListingModel;
// rQuickBook.DataBind();
// rFeatured.DataSource = _eventListingModel.Take(4);
// rFeatured.DataBind();
EventListingViewModel _eventListingViewModel = new EventListingViewModel();
List<EventListingModel> _eventListingModel = new List<EventListingModel>();
_eventListingModel = _eventListingViewModel.GetEventListing();
rcontent.DataSource = _eventListingModel.Take(4);
rcontent.DataBind();
rQuickBook.DataSource = _eventListingModel;
rQuickBook.DataBind();
rFeatured.DataSource = _eventListingModel.Take(4);
rFeatured.DataBind();
}
catch (Exception ex)
{
ErrHandler.WriteError(ex.Message);
}
}
示例5: GetByFilter
public List<TimeSpend> GetByFilter(TaskFilter filter)
{
var listTimeSpend = new List<TimeSpend>();
while (true)
{
var timeSpend = _timeSpendDao.GetByFilter(filter);
timeSpend = GetTasks(timeSpend).FindAll(r => ProjectSecurity.CanRead(r.Task));
if (filter.LastId != 0)
{
var lastTimeSpendIndex = timeSpend.FindIndex(r => r.ID == filter.LastId);
if (lastTimeSpendIndex >= 0)
{
timeSpend = timeSpend.SkipWhile((r, index) => index <= lastTimeSpendIndex).ToList();
}
}
listTimeSpend.AddRange(timeSpend);
if (filter.Max <= 0 || filter.Max > 150000) break;
listTimeSpend = listTimeSpend.Take((int)filter.Max).ToList();
if (listTimeSpend.Count == filter.Max || timeSpend.Count == 0) break;
if (listTimeSpend.Count != 0)
filter.LastId = listTimeSpend.Last().ID;
filter.Offset += filter.Max;
}
return listTimeSpend;
}
示例6: filteredNews
public static string filteredNews(string _url, string _xpath, int _qty, string _categories, string _colleges, string _tags, string _fromDate, string _toDate, int _pageStart)
{
LocalItems xml = new LocalItems(_url, _xpath);
// get count for pagination
// start filtering ....
List<EtsuRssItem> EtsuItemList = new List<EtsuRssItem>();
string o = "<ul class=\"rss_hidelist\">";
xml.items.ToList().ForEach(
x =>
{ EtsuRssItem currentEtsuItem = x.ToEtsuRssItem();
if (currentEtsuItem.dateIsGood(_fromDate, _toDate) &&
currentEtsuItem.hasCategory(_categories) &&
currentEtsuItem.hasAllColleges(_colleges) &&
currentEtsuItem.hasAllTags(_tags))
{ EtsuItemList.Add(currentEtsuItem); }
}
);
EtsuItemList.Take(_qty).ToList().ForEach(
x =>
{
o += x.ToDefault();
});
o += "</ul>";
return o;
}
示例7: Use
public override void Use(SteamID room, SteamID sender, string[] args)
{
new Thread(() =>
{
string arg = String.Join(" ", args);
var distances = new List<Tuple<int, string>>();
foreach (string s in File.ReadAllLines("enable1.txt"))
{
int dist = Compute(arg, s);
if (dist == 0)
{
Chat.Send(room, "This word isn't misspelled!");
return;
}
distances.Add(new Tuple<int, string>(dist, s));
}
distances.Sort((t1, t2) => t1.Item1.CompareTo(t2.Item1));
Chat.Send(room, string.Format("Did you mean: {0}?", string.Join(", ", distances.Take(4))));
}).Start();
}
示例8: Write
public void Write(Storage storage, string fileSpecificPath, string fileWordsPath)
{
var bitmap = new List<byte>();
var words = GenerateWordsStringAndBitmap(bitmap, storage);
if (words == null || words == "")
return;
var bytemap = new List<byte>();
while (bitmap.Count > 0)
{
var oneByte = bitmap.Take(8).ToList();
bitmap = bitmap.Skip(8).ToList();
bytemap.Add(oneByte.Aggregate((byte)0, (result, bit) => (byte)((result << 1) | bit)));
}
using (var streamWriter = new StreamWriter(fileWordsPath))
{
streamWriter.Write(words);
}
using (var fileStream = new FileStream(fileSpecificPath, FileMode.OpenOrCreate))
{
fileStream.Write(bytemap.ToArray(), 0, bytemap.Count);
fileStream.Close();
}
}
示例9: Main
public static void Main()
{
Console.Write("Enter the first number: ");
Queue<int> queue = new Queue<int>();
int number = 0;
string input = Console.ReadLine();
if (!int.TryParse(input, out number))
{
string message = string.Format(TextFormatErrorMessage, input);
throw new InvalidCastException(message);
}
queue.Enqueue(number);
int counter = 1;
List<int> result = new List<int>();
while (counter < Length)
{
queue.Enqueue(queue.Peek() + 1);
queue.Enqueue((2 * queue.Peek()) + 1);
queue.Enqueue(queue.Peek() + 2);
result.Add(queue.Dequeue());
counter += 3;
}
while (queue.Count != 0)
{
result.Add(queue.Dequeue());
}
Console.WriteLine(string.Join(", ", result.Take(50)));
}
示例10: GetRankings
public static List<Models.GameContext.Guild> GetRankings(int topNumber = 0, Models.GameContext.GuildRankingOrderBy orderBy = GuildRankingOrderBy.Score)
{
List<Models.GameContext.Guild> guilds = new List<Models.GameContext.Guild>();
using (var context = new GameDbContext())
{
guilds = context.Guilds.ToList();
if(orderBy == GuildRankingOrderBy.Name)
{
guilds = guilds.OrderByDescending(x => x.G_Name).ToList();
}
if(orderBy == GuildRankingOrderBy.Score)
{
guilds = guilds.OrderByDescending(x => x.G_Score).ToList();
}
if(topNumber > 0)
{
guilds = guilds.Take(topNumber).ToList();
}
}
return guilds;
}
示例11: GetSeasons_WithFolders_ReturnsSeasons
public async Task GetSeasons_WithFolders_ReturnsSeasons()
{
// Arrange
const string path = @"C:\Folder";
List<string> seasonFolders = new List<string>
{
@"C:\Folder\Season 1",
@"C:\Folder\Season 2",
@"C:\Folder\Specials"
};
_fileSystemService.FindDirectories(path, "Season *")
.Returns(seasonFolders.Take(2).ToTask());
_fileSystemService.FindDirectories(path, "Special*")
.Returns(seasonFolders.Skip(2).ToTask());
// Act
IEnumerable<Season> seasons = await _service.GetSeasons(path);
// Assert
List<string> actualSeasonFolders = seasons.Select(s => s.Path).ToList();
Assert.Equal(seasonFolders.Count, actualSeasonFolders.Count);
// Seasons are sorted by season number
Assert.Equal(seasonFolders[0], actualSeasonFolders[1]);
Assert.Equal(seasonFolders[1], actualSeasonFolders[2]);
Assert.Equal(seasonFolders[2], actualSeasonFolders[0]);
}
示例12: RequestFileEdit
public override void RequestFileEdit (IEnumerable<FilePath> files)
{
base.RequestFileEdit (files);
if (!IdeApp.IsInitialized)
return;
List<FilePath> readOnlyFiles = new List<FilePath> ();
foreach (var f in files) {
if (File.Exists (f) && File.GetAttributes (f).HasFlag (FileAttributes.ReadOnly))
readOnlyFiles.Add (f);
}
string error;
if (readOnlyFiles.Count == 1)
error = GettextCatalog.GetString ("File {0} is read-only", readOnlyFiles [0].FileName);
else if (readOnlyFiles.Count > 1) {
var f1 = string.Join (", ", readOnlyFiles.Take (readOnlyFiles.Count - 1).ToArray ());
var f2 = readOnlyFiles [readOnlyFiles.Count - 1];
error = GettextCatalog.GetString ("Files {0} and {1} are read-only", f1, f2);
} else
return;
var btn = new AlertButton (readOnlyFiles.Count == 1 ? GettextCatalog.GetString ("Make Writtable") : GettextCatalog.GetString ("Make Writtable"));
var res = MessageService.AskQuestion (error, GettextCatalog.GetString ("Would you like MonoDevelop to attempt to make the file writable and try again?"), btn, AlertButton.Cancel);
if (res == AlertButton.Cancel)
throw new UserException (error) { AlreadyReportedToUser = true };
foreach (var f in readOnlyFiles) {
var atts = File.GetAttributes (f);
File.SetAttributes (f, atts & ~FileAttributes.ReadOnly);
}
}
示例13: projEval
private double projEval(int[][] input, List<IntPoint> pts)
{
if (pts.Count() > 1) {
pts = pts.Take(1).ToList();
}
double output = 1;
foreach (var p in pts) {
double refEval;
double ref2Eval;
if (HashedResults.ContainsKey(Ref.Eval)) {
refEval = HashedResults[Ref.Eval];
} else {
refEval = Ref.Eval(input);
}
if (HashedResults.ContainsKey(Ref2.Eval)) {
ref2Eval = HashedResults[Ref2.Eval];
} else {
ref2Eval = Ref2.Eval(input);
}
output = this.weight * refEval -
(1 - this.weight) * ref2Eval;
}
HashedResults[Eval] = output;
return output;
}
示例14: BindArticle
public void BindArticle()
{
var list = new List<Resource>();
if (IsOnline)
{
var __courses = CurrentUser.Taught.Where(o => o.State < State.审核).Select(o => o.CourseId).ToList();
foreach (var __c in __courses)
{
list.AddRange(HomoryContext.Value.Resource.Where(o => o.State == State.启用 && o.UserId == CurrentUser.Id && o.ResourceCatalog.Count(p => p.CatalogId == __c && p.State < State.启用) > 0).Take(Count).ToList());
if (list.Count >= Count)
break;
}
}
list = list.OrderByDescending(o => o.Time).ToList();
if (list.Count < Count)
{
list.AddRange(HomoryContext.Value.Resource.Where(o => o.State < State.审核 && o.Type == ResourceType.视频)
.OrderByDescending(o => o.Credit)
.Take(Count - list.Count)
.ToList());
}
homory_article.DataSource = list.Take(Count);
homory_article.DataBind();
}
示例15: PowersetRecursive
private static List<List<int>> PowersetRecursive(List<int> set)
{
var result = new List<List<int>>();
// Base case
if (!set.Any())
{
// Add the empty set
result.Add(new List<int>());
return result;
}
// Recursive case
// Will exist, since otherwise we would have returned before on the base case
int head = set.Last();
// Get the tail of the set by skipping the head or first item
List<int> tail = set.Take(set.Count() - 1).ToList();
List<List<int>> subsets = PowersetRecursive(tail);
result.AddRange(subsets);
// Need to create a copy (i.e. clone);
var newSubsets = new List<List<int>>(subsets);
foreach (List<int> subset in subsets)
{
var newSubset = new List<int>(subset);
newSubset.Add(head);
newSubsets.Add(newSubset);
}
result = newSubsets;
return result;
}