Is there a naming convention for "linq" methods? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Is there any naming convention for "utility" methods whose only reason of existence is to make your Linq statements clearer?
Example:
List<Member> myList = GetMembers();
myList.Where(AllMembersAreBlue);
//lots of code...
public bool AllMembersAreBlue(Member member)
{
//code
}
What would be the most correct way to name methods like the mentioned above (AllMembersAreBlue) ? Is there any convention?
I did some googling and found no answers.

As long as you understand the intent I'd say use whatever name suits you.
In this case I don't really see the point of a separate method, though:
myList.Where(m => m.Members.All(x => x.Color == Color.Blue))

Related

What is the fastest way to get a hash of a collection [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to make an extension method in C# that takes in a collection of objects and can make a hash from it. The problem is I haven't been able to figure out a fast way of doing it. I am trying to have it be done in O(1) time but I haven't found any useful information out there. This is what I currently have but it is slow and doesn't really work (its just an example):
public static int GetCollectionHash(this IEnumerable collection)
{
HashCode hash = new();
foreach (var o in collection)
{
hash.Add(o);
}
return hash.ToHashCode();
}
the only way to do what you want is to create your own collection and overriding the add/remove/etc method and update a private variable that contain the hash when they are called
at that point, just read that new variable

Performance difference between passing a variable to the function and list to the function [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
void MyFunc(int var)
{
// Some Code
}
void MyFunc(List<int> varList)
{
// Some Code
}
What is the performance of parameter passing to these two functions?
There answer is, there should be little difference.
The first is allocating an int and copying the value type of a int,
The second is allocating an reference and copying a reference (which for all intents-and-purposes is an uint / ulong)
There is no appreciable difference.
However, the bigger problem is why you are care about these micro-optimisations, i think you are over thinking this. You can always test this for your self. Either look at the jitted asm, or download BenchmarkDotNet and run a performance test

Need help to interpret this. I am a beginner in C# [closed]

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 6 years ago.
Improve this question
I been searching for ages about IEnumerable online but they are all in the program.cs file.
Can anyone please tell me what is it at the below code?
namespace customBank.Interfaces
{
public class Bank : customBank // the bank take the format of customBank as interface.
{
public IEnumerable<IStatementRow> GetMiniStatement(IAccount account)
}
}
IEnumerable is a list of "things" that you can loop through. In this situation, it is a list of IStatementRow things.
A list of IStatementRow things is returned when the GetMiniStatement function is called.
See: IEnumerable Interface
Also see: Interfaces
Once you read that you will understand pretty well whats happening on your code.

Passing List into method [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Simple question I think. I am trying to pass in a list that I created within my Main into a method. I am missing something but can't quite put my finger on it.
Declaration
List<string> emulationList = new List<string>();
Method Call
sataHeader = ParseSataHeader(sataHeader, bcuFileName, List<string> emulationList);
Method Implementation
private static string ParseSataHeader(string sataHeader, string bcuFileName, List<string> emulationList)
{
//some code
}
You don't specify the type when passing arguments.
Change your second snippet to:
sataHeader = ParseSataHeader(sataHeader, bcuFileName, emulationList);
And it will work just fine.

What is better when using constructor parameters? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Ill start with an example or two. Take the following sample class:
class Sample
{
private object _someObject;
public Sample(object someobject)
{
_someObject = someobject;
// If I then wanted to pass someobject to a method within the constructor,
// is it better to use the field version or the parameter version. Example:
SomeMethod(someobject);
// OR
SomeMethod(_someObject);
}
}
Additionally, I have just finished the book titled "Efficient C#" by Bill Wagner and would like to know if there are any more books out there with a similar format as this one.
I am interested in knowing why I should write code the way it is written (More efficient IL for example)
Thanks in advance guys :)
It makes no difference, they're all references to the same object.

Categories

Resources