When to use List<T>, IEnumerable<T> and ArrayList
By : Sushan Rungta
Date : March 29 2020, 07:55 AM
wish of those help If I understand what you're doing correctly, you have a query like from Inventory i in db select i and then you do several operations on the result: code :
var count = result.Count();
var fifth = result.ElementAt(5);
var allItems = result.ToList();
var result = from Inventory i in db select i;
IQueryable<Inventory> result = from Inventory i in db select i;
IEnumerable<Inventory> result = from Inventory i in db select i;
List<Inventory> result = (from Inventory i in db select i).ToList();
|
Should my IEnumerable enumerate IEnumerable which is passed as a parameter to method like AddRange()?
By : Nassir Mohaya
Date : March 29 2020, 07:55 AM
Hope this helps List.AddRange will behave differently depending on whether the sequence it's passed implements ICollection. In the first case, List implements ICollection, so AddRange can call CopyTo to do a bulk copy. In the second you're just passing in an arbitrary IEnumerable, so it has to iterate over it in order to proceed. Fundamentally you're doing something odd in the second case though. The simple answer is not to do that. I wouldn't expect the results to be guaranteed - it should be up to the implementation whether it eagerly iterates over the passed in sequence and then copies it, or whether it does it lazily. Either implementation will work fine for any sane sequence.
|
Assign ArrayList element if int variable is equal to position in ArrayList
By : sanumula
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Actually, your arrayList contains "MyObject"s. Try calling the toString method. myName = myArrayList.get(i).toString();
|
Get data from IEnumerable using IEnumerable<string> as a parameter
By : Sz. Róbert
Date : March 29 2020, 07:55 AM
like below fixes the issue If the second enumerable is a long sequence you are probably (benchmark to check) better off doing two passes and creating a hash-set, rather than doing the O(N * M) algorithm. The O(N * M) one would be: code :
first.Where(x => second.Contains(x.firstString)).Select(x => x.secondString)
var hashSet = new HashSet<string>(second);
first.Where(x => hashSet.Contains(x.firstString)).Select(x => x.secondString)
|
assign one ArrayList string value to another ArrayList element
By : Mahmoud Hassan
Date : March 29 2020, 07:55 AM
will help you Do one thing Create a constuctor testbean class and assign your value to it when you initialize it. code :
public testbean(String start, String end) {
this.start = start;
this.end = end;
}
|