Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a list I want to remove the column RiskRegisterEntryId and RiskRegisterTypeId how can I to do that..?
SeriesNumber RiskRegisterEntryId RiskRegisterTypeId RiskRegisterType
RCMSRA19111300001 1 1 Site Risk Audit
RCMSRA19111300002 2 1 Site Risk Audit
RCMSRA19111300003 3 1 Site Risk Audit
RCMSRA19111300004 4 1 Site Risk Audit
RCMSRA20111300016 16 1 Site Risk Audit
You can just create a new list of an anonymous type without those columns:
var newList = myList.Select(l => new {
l.SeriesNumber , l.RiskRegisterType
}).ToList();
List.Select(x => new { x.SeriesNumber, x.RiskRegisterType});
This will create a list with an anonymous type containing only those two fields.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
The community reviewed whether to reopen this question 8 days ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I really don't understand why stackoverflow, keeps closing my question as if I already know the answer. That's the reason I am asking.
Add details and clarify the problem you’re solving. This will help others answer the question. You can edit the question or post a new one.
I do have a problem with the logic itself, I don't need to add the whole model and view models to ask how to add or retrieve a dictionary.
The idea is to add about 9 different LISTS,
List<int>All`
trying to add a dictionary. or whatever helps me to retain those 9 lists and a key for each.
Dictionary<int, List<IDS>> CollectionID = new Dictionary<int,List<IDS>>();
Here's what I have:
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(result);
All = myDeserializedClass.Data;
foreach (var item in All)
{
var id = item.ID;
Dictionary<int, List<IDS>> CollectionID = new Dictionary<int,List<IDS>>();
CollectionID.Add(id, All); //is not adding.
}
Question 1. How can I capture the id located inside List<int>>All and add it as the key for the dictionary without the use foreach()?
Question 3. How do I retrieve such a dictionary by using the key?
var allIds = JsonConvert.DeserializeObject<List<IDS>>
the images are only to show that the list is getting add it, however, the count is always 1, so it should be 9.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to return a person's name when we search for a hobby and it should return empty when there are no matching hobbies.
There are many ways to skin this cat. Using Linq is probably the most standard.
The operation you want to do is to select the Key of the dictionary where the value (the array of hobbies) contains the string "Yoga"
val keys = hobbies.Where(keyvalue => keyvalue.contains("Yoga")).Select(keyvalue => keyvalue.key);
now you have a sequence of keys where one of the hobbies is Yoga.
If there is only a single one, and it's an error if there are more, get CC with keys.Single().
If there could be zero or more, and you just want an arbitrary one, you want keys.FirstOrDefault() which returns null if there isn't one.
In between you have SingleOrDefault() for 0 or 1, or First() for 1 or more select an arbitrary one.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
https://www.youtube.com/watch?v=K1xrlc32Tmw&list=PLJUoF2h8Z-brW94dTZ-ZIOhjFq90_lt5K&index=9
4:25 adds a new object in the lineCollection if product does not exist in lineCollection, but at 24:25 it shows duplicating orders? Did i misunderstood how it works?
https://github.com/jedjad/GitHubVS2013
Because the products in duplicate values are not same objects. They may have same names, quantity etc, but initializing a class with same values does not mean that it is the same object as the one initialized before. They are like 2 different apples with same color and size.
If you say that 2 products are same whenever the names are same, then implement IEquatable<Product> in Product class.
public bool Equals(Product other)
{
return Name == other.Name;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two IEnumerable data collections that I would like to compare and get first collection values selected.
Here is what I am trying to do.
ClassA
Column|IsMatched
----
1
2
2
2
3
4
5
ClassB
Column
1
2
7
3
5
2
After comparison, I would like to get following.
ClassA
Column|IsMatched
1 true
2 true
2 true
2 false
3 true
6 false
5 true
4 false
Second collection may be in any order.
Any help to sort this issue would be really appreciated.
Thanks
You could do something like the following:
var workingBag = new List<int>(secondCollection);
var results = firstCollection.Select(i => new ClassA(i, workingBag.Remove(i));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have comma-separated data in my column called col1, and I have an array of strings
IEnumerable<string> year = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000"}
I have tried the following
searchfrom = searchfrom.Where(x => years.Contains(x.col1.Replace(',', ' '))).ToList();
and
searchfrom = searchfrom.Where(x => years.Contains(x.col1)).ToList();
I want that row which is match any "year" into "col1"
To optimize such queries, you should first convert your years collection into a hash set.
var years = new HashSet<string>(new [] { "1990", "1991", ... });
In your Where clause, you need to split the contents of each of your records, x, for which you can use x.Split(','). Then, you need to check whether any of these subparts are contained within the years collection.
var result = searchfrom.Where(x =>
x.Split(',').Any(years.Contains)
).ToList();