本文整理汇总了C#中HashSet.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.AsEnumerable方法的具体用法?C# HashSet.AsEnumerable怎么用?C# HashSet.AsEnumerable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.AsEnumerable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: hash
public void hash() {
decimal beløb1 = 11.5M;
decimal beløb2 = beløb1 / 3M;
beløb2 *= 3M;
/*
True
40270000
BFD9000F
True
False
False
True*/
Console.WriteLine(beløb1 == beløb2); // (A)
Console.WriteLine(beløb1.GetHashCode().ToString("X8")); // (B)
Console.WriteLine(beløb2.GetHashCode().ToString("X8")); // (C)
var list = new List<decimal> { beløb1, };
Console.WriteLine(list.Contains(beløb2)); // (D)
var mgd = new HashSet<decimal> { beløb1, };
Console.WriteLine(mgd.Contains(beløb2)); // (E)
Console.WriteLine(mgd.AsEnumerable().Contains(beløb2)); // (F)
Console.WriteLine(mgd.Where(d => true).Contains(beløb2)); // (G)
}
示例2: Customers
public IHttpActionResult Customers()
{
var customers = _salesService.GetCustomers();
ICollection<CustomerDto> customersDto = new HashSet<CustomerDto>();
foreach (var customer in customers)
customersDto.Add(new CustomerDto() { Id = customer.Id, Name = customer.Name });
return Ok(customersDto.AsEnumerable());
}
示例3: Vendors
public IHttpActionResult Vendors()
{
var vendors = _purchasingService.GetVendors();
ICollection<VendorDto> vendorsDto = new HashSet<VendorDto>();
foreach (var vendor in vendors)
vendorsDto.Add(new VendorDto() { Id = vendor.Id, Name = vendor.Name });
return Ok(vendorsDto.AsEnumerable());
}
示例4: Accounts
public IHttpActionResult Accounts()
{
var accounts = _financialService.GetAccounts();
ICollection<AccountDto> accountsDto = new HashSet<AccountDto>();
foreach (var account in accounts)
accountsDto.Add(new AccountDto() { Id = account.Id, AccountName = account.AccountName });
return Ok(accountsDto.AsEnumerable());
}
示例5: Contacts
public IHttpActionResult Contacts()
{
var contacts = _salesService.GetContacts();
ICollection<ContactDto> contactsDto = new HashSet<ContactDto>();
foreach (var contact in contacts)
contactsDto.Add(new ContactDto() { Id = contact.Id, FirstName = contact.FirstName, LastName = contact.LastName });
return Ok(contactsDto.AsEnumerable());
}
示例6: ItemTaxGroups
public IHttpActionResult ItemTaxGroups()
{
var itemtaxgroups = _financialService.GetItemTaxGroups();
ICollection<ItemTaxGroupDto> itemtaxgroupsDto = new HashSet<ItemTaxGroupDto>();
foreach (var itemtaxgroup in itemtaxgroups)
itemtaxgroupsDto.Add(new ItemTaxGroupDto() { Id = itemtaxgroup.Id, Name = itemtaxgroup.Name });
return Ok(itemtaxgroupsDto.AsEnumerable());
}
示例7: Items
public IHttpActionResult Items()
{
var items = _inventoryService.GetAllItems();
ICollection<ItemDto> itemsDto = new HashSet<ItemDto>();
foreach (var item in items)
itemsDto.Add(new ItemDto() { No = item.No, Description = item.Description });
return Ok(itemsDto.AsEnumerable());
}
示例8: ItemCategories
public IHttpActionResult ItemCategories()
{
var itemcategories = _inventoryService.GetItemCategories();
ICollection<ItemCategoryDto> itemcategoriesDto = new HashSet<ItemCategoryDto>();
foreach (var itemcategory in itemcategories)
itemcategoriesDto.Add(new ItemCategoryDto() { Id = itemcategory.Id, Name = itemcategory.Name });
return Ok(itemcategoriesDto.AsEnumerable());
}
示例9: GetPeople
public Dictionary<string,Person> GetPeople(HashSet<String> ids, HashSet<String> fields, CollectionOptions options)
{
var result = new Dictionary<string, Person>();
var persons = db.persons.Where(x => ids.AsEnumerable().Contains(x.id.ToString()));
// TODO filter first then fill dictionary
foreach (var p in persons)
{
int personId = p.id;
var name = new Name();
var person = new Person();
name.givenName = p.first_name;
name.familyName = p.last_name;
name.formatted = p.first_name + " " + p.last_name;
person.displayName = name.formatted;
person.name = name;
person.id = personId.ToString();
if (fields.Contains("about_me") || fields.Contains("@all"))
{
person.aboutMe = p.about_me;
}
if (fields.Contains("age") || fields.Contains("@all"))
{
person.age = p.age;
}
if (fields.Contains("children") || fields.Contains("@all"))
{
person.children = p.children;
}
if (fields.Contains("date_of_birth") || fields.Contains("@all"))
{
if (p.date_of_birth.HasValue)
{
person.birthday = UnixTime.ToDateTime(p.date_of_birth.Value);
}
}
if (fields.Contains("ethnicity") || fields.Contains("@all"))
{
person.ethnicity = p.ethnicity;
}
if (fields.Contains("fashion") || fields.Contains("@all"))
{
person.fashion = p.fashion;
}
if (fields.Contains("happiest_when") || fields.Contains("@all"))
{
person.happiestWhen = p.happiest_when;
}
if (fields.Contains("humor") || fields.Contains("@all"))
{
person.humor = p.humor;
}
if (fields.Contains("job_interests") || fields.Contains("@all"))
{
person.jobInterests = p.job_interests;
}
if (fields.Contains("living_arrangement") || fields.Contains("@all"))
{
person.livingArrangement = p.living_arrangement;
}
if (fields.Contains("looking_for") || fields.Contains("@all"))
{
person._lookingFor = p.looking_for;
}
if (fields.Contains("nickname") || fields.Contains("@all"))
{
person.nickname = p.nickname;
}
if (fields.Contains("pets") || fields.Contains("@all"))
{
person.pets = p.pets;
}
if (fields.Contains("political_views") || fields.Contains("@all"))
{
person.politicalViews = p.political_views;
}
if (fields.Contains("profile_song") || fields.Contains("@all"))
{
if (!string.IsNullOrEmpty(p.profile_song))
{
person.profileSong = new Url(p.profile_song, "", "");
}
}
if (fields.Contains("profileUrl") || fields.Contains("@all"))
{
person.profileUrl = urlPrefix + "/profile/" + personId;
}
if (fields.Contains("profile_video") || fields.Contains("@all"))
{
if (!string.IsNullOrEmpty(p.profile_video))
{
person.profileVideo = new Url(p.profile_video, "", "");
}
}
if (fields.Contains("relationship_status") || fields.Contains("@all"))
{
person.relationshipStatus = p.relationship_status;
}
//.........这里部分代码省略.........
示例10: GetAppData
public DataCollection GetAppData(HashSet<String> ids, HashSet<String> keys, String appId)
{
var data = new Dictionary<string, Dictionary<string, string>>();
var res = db.application_settings
.Where(x => (!String.IsNullOrEmpty(appId)?x.application_id.ToString() == appId : true) && ids.AsEnumerable().Contains(x.person_id.ToString()) && (keys.Count == 0 ? true : keys.AsEnumerable().Contains(x.name)))
.Select(x => new { x.person_id, x.name, x.value });
foreach (var re in res)
{
if (!data.ContainsKey(re.person_id.ToString()))
{
data.Add(re.person_id.ToString(), new Dictionary<string, string>());
}
data[re.person_id.ToString()].Add(re.name, re.value);
}
return new DataCollection(data);
}
示例11: DeleteActivities
public bool DeleteActivities(string userId, string appId, HashSet<string> activityIds)
{
var res =
db.activities.Where(
x => activityIds.AsEnumerable().Contains(x.id.ToString()) && x.person_id.ToString() == userId && x.app_id.ToString() == appId);
db.activities.DeleteAllOnSubmit(res);
db.SubmitChanges();
return (db.GetChangeSet().Deletes.Count == 0);
}
示例12: GetUniqueContentCategories
/// <summary>
/// Given a set of content templates, is capable of returning their
/// </summary>
/// <param name="contentTemplates"></param>
/// <returns></returns>
private IEnumerable<string> GetUniqueContentCategories(IEnumerable<IContentTemplate> contentTemplates)
{
var categorySet = new HashSet<string>();
foreach (var template in contentTemplates)
{
if (!string.IsNullOrEmpty(template.VirtualCategory))
categorySet.Add(template.VirtualCategory);
}
return categorySet.AsEnumerable();
}
示例13: GetActivities
public List<Activity> GetActivities(HashSet<string> ids, string appId, HashSet<String> fields, CollectionOptions options)
{
var activities = db.activities
.OrderByDescending(x => x.id)
.Where(x => ids.AsEnumerable().Contains(x.person_id.ToString()) && (string.IsNullOrEmpty(appId)?true:x.app_id.ToString() == appId));
int first = options.getFirst();
int max = options.getMax();
if (first != 0)
{
activities = activities.Skip(first);
}
if (max != 0)
{
activities = activities.Take(max);
}
List<Activity> actList = new List<Activity>();
foreach (var row in activities)
{
var act = new Activity(row.id.ToString(), row.person_id.ToString());
act.streamTitle = "activities";
act.title = row.title;
act.body = row.body;
act.postedTime = row.created;
act.mediaItems = GetMediaItems(row.id.ToString());
actList.Add(act);
}
return actList;
}
示例14: GetCorrections
public Tuple<IEnumerable<int>, FunctionPerfData> GetCorrections(string word)
{
Stopwatch sw = new Stopwatch();
sw.Start();
FunctionPerfData fpd = new FunctionPerfData();
#region Get corrections with edit distance 1
FunctionPerfData stagePerfData = new FunctionPerfData();
fpd.StagesPerfData.Add("GetCandidates1", stagePerfData);
HashSet<int> ret = new HashSet<int>();
Stopwatch sws = new Stopwatch();
sws.Start();
List<CandidateWord> candidates = GetCorrectionsWithEditDistanceOne(new CandidateWord(word, 0)).ToList();
sws.Stop();
stagePerfData.TimeTaken = sws.ElapsedMilliseconds;
stagePerfData.OtherData.Add("Num Actual Candidates", candidates.Count);
stagePerfData.OtherData.Add("Num Candidates Formula", "52N + 25");
stagePerfData.OtherData.Add("Num Candidates by Formula", (52 * word.Length + 25));
#endregion
#region Get corrections with edit distance 2
sws = new Stopwatch();
sws.Start();
stagePerfData = new FunctionPerfData();
fpd.StagesPerfData.Add("GetCandidates2", stagePerfData);
List<CandidateWord> copy = new List<CandidateWord>(candidates);
foreach (CandidateWord c in copy)
{
candidates.AddRange(GetCorrectionsWithEditDistanceOne(c));
}
sws.Stop();
stagePerfData.TimeTaken = sws.ElapsedMilliseconds;
stagePerfData.OtherData.Add("Num Actual Candidates", candidates.Count);
stagePerfData.OtherData.Add("Num Candidates Formula", "(52N + 25)(52N + 25)");
stagePerfData.OtherData.Add("Num Candidates by Formula", (52 * word.Length + 25) * (52 * word.Length + 25));
#endregion
#region Get unique candidates
sws = new Stopwatch();
sws.Start();
stagePerfData = new FunctionPerfData();
fpd.StagesPerfData.Add("GetCandidatesUnique", stagePerfData);
//HashSet<string> hs = new HashSet<string>(candidates.Select(x => x.Word));
IEnumerable<string> hs = candidates.Select(x => x.Word).Distinct();
stagePerfData.OtherData.Add("Unique Candidates", hs.Count());
sws.Stop();
stagePerfData.TimeTaken = sws.ElapsedMilliseconds;
#endregion
#region Filter valid candidates
sws = new Stopwatch();
sws.Start();
stagePerfData = new FunctionPerfData();
fpd.StagesPerfData.Add("FilterValidCandidates", stagePerfData);
foreach(string c in hs)
{
var positions = this.FindWord(c);
if(positions.Any())
{
ret.Add(positions.First());
}
}
sws.Stop();
stagePerfData.TimeTaken = sws.ElapsedMilliseconds;
#endregion
fpd.TimeTaken = sw.ElapsedMilliseconds;
return new Tuple<IEnumerable<int>,FunctionPerfData>(ret.AsEnumerable(), fpd);
}
示例15: MatchResults
/// <summary>
/// Return an IEnumerable of PDAResults after applying this PDA to the
/// given input.
/// </summary>
public IEnumerable<PDAResult> MatchResults(string input)
{
// Catch empty initial string, which trivially matches an empty
// stack acceptance PDA.
if (input == "")
{
return new List<PDAResult> { new PDAResult(0, 0, true) };
}
// If there are no transitions that can move on the initial
// configuration, or can remove items from the stack, fail quickly.
if (!Transitions.Any(t => t.StackHead == '_' &&
t.OldState == StartState &&
t.InputChar == input[0]) ||
!Transitions.Any(t => t.StackReplace.Length == 0))
{
return new List<PDAResult> { new PDAResult(0, 0, false) };
}
// HashSet to remove duplicate results.
var resultList = new HashSet<PDAResult>();
var stateList = new List<PDARunState> { new PDARunState(input, 0,
"", StartState) };
while (stateList.Count() > 0)
{
// HashSet to remove duplicate states.
var newStateList = new HashSet<PDARunState>();
foreach (var state in stateList)
{
// Obtain the list of states reachable from this state.
var nextStates = FindNextStates(state).ToList();
// No further states, so fail.
if (nextStates.Count == 0)
{
resultList.Add(new PDAResult(state.MatchedSoFar,
state.Stack.Length,
false));
continue;
}
foreach (var nextState in nextStates)
{
// Check for accept/reject state with acceptance by
// empty stack.
if (nextState.Failure || nextState.Input == "" &&
nextState.Stack.Length == 0)
{
resultList.Add(new PDAResult(nextState.MatchedSoFar,
nextState.Stack.Count(), !nextState.Failure));
}
else
{
newStateList.Add(nextState);
}
}
}
stateList = newStateList.ToList();
}
return resultList.AsEnumerable();
}