C# Join with OrderBy [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 10 months ago.
Improve this question
Here's an example of my code thus far.
#string.Join(", ", #piece.PieceThemes.Select(t => t.Theme.Title).ToArray())
I would like to order the array in descending order. I found that .OrderByDescending() exists, but I'm having trouble understanding how to use it.
Any help is appreciated!

you provide a lamda function to specify the property to sort by
#string.Join(", ", #piece.PieceThemes.Select(t => t.Theme.Title).OrderByDescending(x=> x).ToArray())
in this case x is a string and you can just sort by it.

Related

LINQ Contains based on all properties [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 2 days ago.
Improve this question
Need to read all properties using contains. I want to return a new list where I enter contains with parameter string.
var newlist = list.Contains(text);

If Statement help mutiple and, or statements [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 1 year ago.
Improve this question
if (((Input.GetKeyDown(KeyCode.A)) && (Input.GetKeyDown(KeyCode.LeftShift))) || ((Input.GetKeyDown(KeyCode.RightShift)) && (Input.GetKeyDown(KeyCode.A))))
{
print("Well done! Next Key: " + "A");
}
What's Wrong with this if statement?
It looks like you have too many parentheses on the left side of the OR. Also, your parentheses are not correct on the right side. I believe you want to set it up like this.
if (Input.GetKeyDown(KeyCode.A) && (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)))
Edit: Revised because checking for A twice is redundant as pointed out by #Caius-jard.

How to check are list of objects is different from list of list? [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 3 years ago.
Improve this question
how can I check if an int[] is already in a List<int[]>.
For example:
There is List<int[]> list and an int[] arr and I want to check if all numbers are not the same(order doesn't matter), and if not the same add it to a list. How could I do that?
I can't change the order of list
This is what you want Order then SequenceEqual pattern for each element in the list:
if(!list.Any(a=>a.OrderBy(i1=>i1).SequenceEqual(arr.OrderBy(i2=>i2))))
list.Add(arr);

Convert.ToInt32("example") Collisions? [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 5 years ago.
Improve this question
Will the C# function Convert.ToInt32(text) convert different words to the same int? Any links or pushes in the right direction are appreciated!
P.S.
What about anagrams?
No, Convert.ToInt32(text) will just try to parse your text to an int, like:
Convert.ToInt32("032") will return 32 as int but
Convert.ToInt32("Brian") will throw an exception.
I assume that you want to have some kind of hashing, when you say "different words to the same int".
Try GetHashCode(). It will return the same value if you call it multiple times with the same value, for example:
"Brian".GetHashCode() will always return 1635321435

What does (int) mean 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've encountered sometimes code like this and I am kind of new to programming. I want to find out what's the meaning behind those objects or data type enclosed in parenthesis.
(int)
(datagridview)
(form)
If you see something like this it's called a cast. It's used to explicitly convert a data type to another data type.
double pi = 3.14159;
int my_int = (int)pi;
See this description on casting for more details.

Categories

Resources