C
C#17mo ago
Simo

❔ What is happening under the covers to allow this to work

someRandomString.Split('.').Select(HttpUtility.HtmlDecode); From the definition of HtmlDecode, it has an anonymous constructor, and one which takes a 's' parameter for the string. How on earth is this linq working that it can somehow construct it and pass the string in and get the result?
6 Replies
Angius
Angius17mo ago
bunchOfString.Select(MethodThatTakesString);
bunchOfString.Select(MethodThatTakesString);
is the same as
bunchOfStrings.Select(s => MethodThatTakesString(s));
bunchOfStrings.Select(s => MethodThatTakesString(s));
Omnissiah
Omnissiah17mo ago
HtmlDecode doesn't have a constructor 😐 it's a method
Simo
SimoOP17mo ago
sorry yea a method, said that wrong does it just insert it into the first method that has a single string param?
Angius
Angius17mo ago
Linq's .Select() is defined something like Select<TIn, TOut>(Func<TIn, TOut> func) So any method or function that takes a TIn and returns a TOut will fit (string s) => DoStuffWithString(s) fits the bill, but so does DoStuffWithString() itself
Simo
SimoOP17mo ago
that is pretty wild, I was wondering wtf was going on thank you
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server