本文整理汇总了C#中SortedSet.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Intersect方法的具体用法?C# SortedSet.Intersect怎么用?C# SortedSet.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.Intersect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var s1 = new Set<int>();
s1.Added += (sender, args) => Console.WriteLine("Добавлено: " + args);
s1.Add(8,2,9);
var ss1 = new SortedSet<int>(2, 5, 7, 4);
Console.WriteLine("The first SortedSet: " + ss1);
Console.WriteLine("Приведённое:" + (Set<int>)ss1);
var ss2 = new SortedSet<int>(2, 9, 7, 4);
Console.WriteLine("The second SortedSet: " + ss2);
Console.WriteLine("Intersection: " + ss1.Intersect(ss2));
Console.WriteLine("Union: " + ss1.Union(ss2));
Console.WriteLine("Is the first SortedSet contain " + 5 + ": " + ss1.Contains(5));
Console.ReadKey();
}
示例2: Main
static void Main(string[] args)
{
SortedSet<int> followers = new SortedSet<int>();
SortedSet<int> following = new SortedSet<int>();
followers.Add(1);
followers.Add(2);
followers.Add(14);
following.Add(1);
following.Add(14);
following.Add(3);
foreach(int i in following.Intersect(followers))
Console.WriteLine(i);
}
示例3: HasActiveSubscriptionBasedOnCategoryId
public static CheckSubscriptionReturnObject HasActiveSubscriptionBasedOnCategoryId(User user, IEnumerable<int> categoryIds, DateTime? registDt = null, string CountryCodeViaIp = null)
{
var returnObject = new CheckSubscriptionReturnObject() { HasSubscription = false, Within5DaysOrLess = false, IsFreeEntitlement = false };
try
{
SortedSet<int> completeCategoryIds = new SortedSet<int>();
if (registDt == null)
registDt = DateTime.Now;
if (user != null)
{
if (user.Entitlements != null)
{
if (user.Entitlements.Count(e => e.EndDate > registDt) > 0)
{
foreach (var entitlement in user.Entitlements)
{
if (entitlement.EndDate > registDt)
{
if (entitlement is PackageEntitlement)
{
var pkgEntitlement = (PackageEntitlement)entitlement;
var showIds = pkgEntitlement.Package.GetAllOnlineShowIds(user.CountryCode);
completeCategoryIds.UnionWith(showIds);
}
else if (entitlement is ShowEntitlement)
{
var showEntitlement = (ShowEntitlement)entitlement;
completeCategoryIds.Add(showEntitlement.CategoryId);
}
if (completeCategoryIds.Intersect(categoryIds).Count() > 0)
{
returnObject.HasSubscription = true;
if (returnObject.SubscriptionEndDate == null)
returnObject.SubscriptionEndDate = entitlement.EndDate;
else if (returnObject.SubscriptionEndDate < entitlement.EndDate)
returnObject.SubscriptionEndDate = entitlement.EndDate;
break;
}
}
}
}
}
//after checking entitlements and user still has no subscription
//fallback is to check if shows are available on anonymous and default logged in packages
if (!returnObject.HasSubscription)
{
SortedSet<int> listOfPackageIds = new SortedSet<int>();
listOfPackageIds.Add(GlobalConfig.LoggedInDefaultPackageId);
listOfPackageIds.Add(GlobalConfig.AnonymousDefaultPackageId);
var context = new IPTV2Entities();
var offering = context.Offerings.Find(GlobalConfig.offeringId);
var packages = offering.Packages.Where(p => listOfPackageIds.Contains(p.PackageId));
if (packages != null)
{
if (packages.Count() > 0)
{
foreach (var package in packages)
{
completeCategoryIds.UnionWith(package.GetAllOnlineShowIds(user.CountryCode));
}
}
returnObject.HasSubscription = completeCategoryIds.Intersect(categoryIds).Count() > 0;
returnObject.IsFreeEntitlement = returnObject.HasSubscription;
}
}
if (returnObject.SubscriptionEndDate != null && registDt != null)
{
if (returnObject.SubscriptionEndDate.Value.Subtract((DateTime)registDt).TotalDays <= 3)
{
returnObject.NumberOfDaysLeft = Convert.ToInt32(returnObject.SubscriptionEndDate.Value.Subtract((DateTime)registDt).TotalDays);
returnObject.Within5DaysOrLess = true;
}
}
}
else //Logged out, check default anonymous package
{
var context = new IPTV2Entities();
var offering = context.Offerings.Find(GlobalConfig.offeringId);
var package = offering.Packages.FirstOrDefault(p => p.PackageId == GlobalConfig.AnonymousDefaultPackageId);
var listOfShows = package.GetAllOnlineShowIds(CountryCodeViaIp);
returnObject.HasSubscription = listOfShows.Intersect(categoryIds).Count() > 0;
returnObject.IsFreeEntitlement = returnObject.HasSubscription;
}
}
catch (Exception e) { MyUtility.LogException(e); }
return returnObject;
}