C
Join ServerC#
help
❔ Can't get around on how to instantiate this.
HHercules11/20/2022
I can't get around on how to instantiate this in my service.cs so i can call it properly in my controller.
Relevant code below.
https://paste.mod.gg/kocfivzcagoc/0
Relevant code below.
https://paste.mod.gg/kocfivzcagoc/0
Pphaseshift11/20/2022
Word frequency result is not word frequency
HHercules11/20/2022
Yes i know they are two different types but I'd like to be able to generate Word frequency result
https://paste.mod.gg/kocfivzcagoc/0
https://paste.mod.gg/kocfivzcagoc/0
Pphaseshift11/20/2022
New one up
HHercules11/20/2022
My Challenge is making below to return - Word frequency result @phaseshift
I've tried instantiate Lists
I've tried instantiate Lists
var frequencies =
dict.OrderByDescending(x => x.Value)
.Select(x => new WordFrequency(x.Key, x.Value))
.Take(n)
.ToList();
Pphaseshift11/20/2022
You don't even have new wordfreqresult
HHercules11/20/2022
Shouldn't something like this work?
var frequencies =
dict.OrderByDescending(x => x.Value)
.Select(x => new WordFrequencyResult(new List<List<WordFrequency>>()
{
new WordFrequency(x.Key, x.Value)
}))
.Take(n)
.ToList();
Pphaseshift11/20/2022
Doubt it. Isn't 'result' meant to contain the lists?
HHercules11/20/2022
I do have a
Result is meant to return the values i wish to give as output in my endpoint through Response.cs
public record WordFrequencyResult(List<List<WordFrequency>>? ListOfWordFrequency);
Result is meant to return the values i wish to give as output in my endpoint through Response.cs
Pphaseshift11/20/2022
Yeah, so that should be the last thing you new.
Pphaseshift11/20/2022
Putting it inside linq select is going to make a collection of 'result'
Pphaseshift11/20/2022
var lists = linq stuff
Var result = new Result(lists)
Var result = new Result(lists)
HHercules11/20/2022
Here is a another example but if works fine difference are the type in Result.cs
https://paste.mod.gg/tpnvxlicymuu/0
https://paste.mod.gg/tpnvxlicymuu/0
HHercules11/20/2022
Exactly i need to return a List<WordFrequency> with linq.
But when i do .Select(x => new (starting my instansiations) ) // i get wrong.
But when i do .Select(x => new (starting my instansiations) ) // i get wrong.
Pphaseshift11/20/2022
What type does your linq statement return?
HHercules11/20/2022
List<WordFrequency> right now.
foreach (var dict in stringResult)
{
var frequencies =
dict.OrderByDescending(x => x.Value)
.Select(x => new WordFrequency(x.Key, x.Value))
.Take(n)
.ToList();
}
Pphaseshift11/20/2022
Right. And what does result take?
Pphaseshift11/20/2022
Not that.
Pphaseshift11/20/2022
So you need to figure out how to nest another list
HHercules11/20/2022
If we break down the question.
It would be, how do would you instantiate
WordFrequencyResult takes
And WordFrequency is
It would be, how do would you instantiate
List<List<WordFrequencyResult>>
WordFrequencyResult takes
List<List<WordFrequency>>? ListOfWordFrequency
And WordFrequency is
public record WordFrequency(string Word, long FrequencyCount);
Pphaseshift11/20/2022
What. You want list of list of result?
Pphaseshift11/20/2022
That's four nested lists.
HHercules11/20/2022
Yes otherwise i'll break architectual pattern that i've done. like the Authentication link i sent before
Pphaseshift11/20/2022
Well it's dumb. But it's not complicated
Pphaseshift11/20/2022
Frequencies is only one list
Pphaseshift11/20/2022
So you need another list before you make a result
HHercules11/20/2022
Yes.
HHercules11/20/2022
Im having incompetent problems on getting that list.
Pphaseshift11/20/2022
You make the list before the loop where you make frequencies
Pphaseshift11/20/2022
Then inside that loop, you added frequencies to it
Pphaseshift11/20/2022
Your problem is literally the same as how to add numbers to a list
Pphaseshift11/20/2022
Just replace'numbers' with 'some other list'
HHercules11/20/2022
var test = new List<List<WordFrequencyResult>>();
{
new List<WordFrequencyResult>()
{
new WordFrequencyResult(
new List<List<WordFrequency>>()
{
new List<WordFrequency>()
{
new WordFrequency("s", 2)
}
}
)
};
};
HHercules11/20/2022
4 lists yes you're right.
Pphaseshift11/20/2022
So problem is solved? You know how to do it
HHercules11/20/2022
Nope, This gave me List<List<List<WordFrequencyResult>>>
Pphaseshift11/20/2022
'this'?
HHercules11/20/2022
The code above xD
Pphaseshift11/20/2022
How
Pphaseshift11/20/2022
You just need to pay more attention
HHercules11/20/2022
Yes, I managed to solve it now, all thanks to you - it's about thinking and working on single things and not over complicate it.
HHercules11/20/2022
And you actually helped me realize that my achitecture is dumb. but i think if my application was much much bigger it wouldn't be so dumb
AAccord11/22/2022
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.