本文整理汇总了C#中Entities.List.First方法的典型用法代码示例。如果您正苦于以下问题:C# List.First方法的具体用法?C# List.First怎么用?C# List.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entities.List
的用法示例。
在下文中一共展示了List.First方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshHierarchyPostCache
private byte[] RefreshHierarchyPostCache(List<HierarchyPost> hierarchyPosts)
{
var serializedPosts = JsonConvert.SerializeObject(hierarchyPosts, new JsonSerializerSettings {DefaultValueHandling = DefaultValueHandling.Ignore});
var gzippedPosts = Gzipper.Zip(serializedPosts);
var root = hierarchyPosts.First();
if (root.RootId != root.PostId)
{
throw new ArgumentException($"Can't refresh cache for Hierarchy post because the first post has value of RootId {root.RootId} and the PostId is {root.PostId}");
}
var key = root.RootId.ToString();
var lastChangeTicks = DateTime.UtcNow.Ticks;
var entries = new[]
{
new HashEntry("Posts", gzippedPosts),
new HashEntry("LastChangeTicks", lastChangeTicks),
new HashEntry("Views", root.Views)
};
_redis.GetDatabase().HashSet(key, entries, CommandFlags.FireAndForget);
var memoryKeyValue = new Tuple<PostMetadata, byte[]>(
new PostMetadata
{
LastChangeTicks = lastChangeTicks,
ViewsCount = root.Views
}, gzippedPosts);
_memoryCache.Set(key, memoryKeyValue);
return gzippedPosts;
}
示例2: FindBookByTag
/// <summary>
/// Finds some book depending on function
/// </summary>
/// <param name="function">Condition to find book</param>
/// <returns>Book</returns>
public Book FindBookByTag(Func<Book, bool> function)
{
Book result = null;
try
{
if (function == null)
{
logger.Error("Error while find book by tag");
throw new ArgumentNullException("Tag is null");
}
books = repository.LoadToList();
result = books.First(function);
logger.Info("Book was found successfully");
}
catch (Exception e)
{
logger.Info(e.Message);
logger.Error(e.StackTrace);
}
return result;
}
示例3: Search
public IEnumerable<KeyValuePair<int, string>> Search(string customerName)
{
if (string.IsNullOrEmpty(customerName) || string.IsNullOrWhiteSpace(customerName))
{
yield return new KeyValuePair<int, string>();
}
var search = new CustomerSearch(new LevenshteinDistance());
IEnumerable<KeyValuePair<int, string>> values = new List<KeyValuePair<int, string>>();
if (_customerRespository.Persistence == Persistence.SQL)
{
values = _customerRespository.All.Select(i => new KeyValuePair<int, string>(i.Id, i.Name)).ToList();
}
else if (_customerRespository.Persistence == Persistence.Graph)
{
var graph = _customerRespository.GraphClient;
values = graph.Cypher.Match("(p:Customer)").Return(p => p.As<CustomerGraph.Node>()).Results
.Select(p => new KeyValuePair<int, string>((int)p.Id, p.Name));
}
foreach (var match in search.FindClosestMatches(customerName, values.Select(i => i.Value), 5))
{
yield return (new KeyValuePair<int, string>(values.First(c => c.Value == match).Key, match));
}
}
示例4: CalculateResultVector
private static Double[] CalculateResultVector(List<Double[]> vectors)
{
List<Double> resultVector = new List<Double>();
Int32 n = vectors.First().Length;
for (Int32 i = 0; i < n; i++)
{
Double tmp = 0;
for (Int32 j = 0; j < vectors.Count; j++)
{
tmp += vectors.ToArray()[j][i];
}
resultVector.Add(tmp / vectors.Count);
}
return resultVector.ToArray();
}