Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

3

Another opportunity to solve this problem is to use Transpose() in MoreLinq with Linq itself: var listoflists = new List<List<string>>() { one, two, three, four, five }; var res = listoflists.Transpose() .SelectMany(x => x) .Take(10); Result: { "aaa", "eee", "ggg", "lll", "1111", "bb", "fff", "hhhhh", "22", "ccc" }


3

A few comments about the API which completely ignore the spec: I would rename N to count, which is descriptive and follows typical naming conventions. Your method would benefit from inline documentation (///), which could clarify the behaviour (what does Extract mean?!?) and describe the parameters precisely. It's good that you've used the general-purpose ...


3

CharlesNRice's solution has still one flaw. It eagerly enumerates the main collection and since we don't know its length, we better avoid it. Since the other answer already mentions flaws in your code, let me just add this lazy alternative. It's a little bit tricky to make it deferred because you first need to enumerate the main collection and create ...


7

Calling ElementAt inside a loop will cause the IEnumerable to be called multiple times. This code isn't deffering execution either. Now if you think the pervious code wasn't readable then hold on to your hats. I'm going to post some code in hopes someone can build on it and maybe come up with something better. public static class IEnumerableExtensions {...


0

just modified the as like string extension public static string GetDescription<T>(this T value) where T : IConvertible { return (value is Enum) ? value .GetType() .GetMember(value.ToString()) .FirstOrDefault() ?.GetCustomAttribute<DescriptionAttribute>() ...


-5

I looked at your code. I like that you're thinking about improving for your future career! Because this is for a new position, we have to assume they're looking for the basics. So of course, comment your code. Another thing I noticed is that the entire project was uploaded in one commit. Now, I know that if you were told to upload your code to a public ...


0

As mentioned by others it's a problem when the size of the input array is lesser than Vector128<sbyte>.Count. You can handle it by taking the min of the two as stepSize: int stepSize = Math.Min(Vector128<sbyte>.Count, array.Length); This is safe because the first for-loop will only run if stepSize > vector size and the first while-loop will ...


2

Correctness if( array.Length <= 0 ) return 0; This piece of code is suspicious. Maybe you should return sbyte.MaxValue, maybe null, or maybe throw ArgumentException. (I can imagine that there were a Max method, both, together is used to find the range of values, then maybe 0 is a valid return value.) This is one of the rare times I'd appreciate a ...


1

Frame challenge I was trying to avoid "complexity", so get rid of 3rd part libs Although it's not strictly code review, I would like to start by challenging this goal. There are many many official Microsoft libraries with dependencies on Newtonsoft.Json. (See this answer on our software engineering sister site). Core code public static string ...


7

if (lookup.ContainsKey(transmitter)) { var receiverLookup = lookup[transmitter]; This searches for the KeyValuePair twice. There's a more efficient approach: if (lookup.TryGetValue(transmitter, out var receiverLookup)) var ungrouped = receivers.Except(blocksTracker).ToArray(); foreach (var receiver in ungrouped) ...


Top 50 recent answers are included