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

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.

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

In Unity3D, update is called on every script all at once. How? [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
How is that accomplished, and could I use the system type myself? Is it abstracts?
Sadly, the exact code for that is called by unity itself and you cant view it with applications like ILSpy.
Essentially though, Unity takes all GameObjects in the active scene and checks their MonoBehaviour script for an update function and if they do, it invokes it.
You could imagine it similar to something like this:
void OnFrameRender ()
{
foreach (GameObject g in allGameObjectsInCurrentScene)
{
MonoBehaviour m = g.GetComponent<MonoBehaviour>();
if (m.GetType().GetMethod("Update") != null)
m.Invoke("Update");
}
// Additional render logic
}
Since Unity itself is coded in C++ and not in C# this is not going to be the exact code but the approach could be similar.

Best way to store bunch of constant values in .NET [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
This is basically a a design question:
I am rewriting an application in C# which is basically written in C++. C++ has this nice concept of Header files which will gold a lot of declared constant values for the consuming file.
However, we do not have Header files in C#. I may have two options
Create a class which will hold a lot of constant values for me(No so standard)
Store values in XML (Standard-But involves a lot of parsing hassle)
Which is a better solution? Is there any other solution that I may not know of?
Personally i'd use a static class and place all the values in there.
public static class Constants
{
public const int Ten = 10;
public const int Twenty = 20;
....
}
EDIT
As #JonSkeet suggested, it's better if you store these values in classes they pertain to, however, that might not always be possible.

Is there a naming convention for "linq" methods? [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 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))

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