Type as Parameter, and string[] from Linq
1. How can I use type this way? Typeof(type) didn't work either.
2.
Rolls
is a string[]. I need to concatenate it from the series but I haven't done that in Linq before. How do?7 Replies
1.) Seems like you need generics for the function too
2.) What do you mean by concatenate? Adding the strings together? you can do that with
string.Join(" ", stringArray);
. You can replace " "
with any string you want to have in between each string in the array 1. How do I do that?
2. I need to return a string[] that is a concatenation of all the Traits' Rolls string[]s
1.) I'd try
GetRolls<T>(AgentHitbox agentHitbox) => agentHitbox.agent.GetTraits<T> ...
But at compile time you wont know if T has a property Rolls
so you have to restrict T to something you know, sooo
2.) You are using Linq, so you can use Aggregate
or i believe SelectMany
could work tooAnd don't forget ToArray at the end
I'll give that a shot, thanks!
Umm You guys rule
In general, if you find yourself using a
System.Type
parameter, you've probably done something wrong 🙂Ah, ok. I'll keep that in mind, thank you!