C
C#•8mo ago
Lvgraef

shorter way of writing x => x.Length()

I thought you could just put string.Length? but you apparently cant? is there no way to write it shorter?
28 Replies
Pobiega
Pobiega•8mo ago
context?
Lvgraef
LvgraefOP•8mo ago
LINQ .Min
Pobiega
Pobiega•8mo ago
oh, you mean Method group syntax
Lvgraef
LvgraefOP•8mo ago
names.Min<string>(x => x.Length()) like cant i do the lambda shorter
Pobiega
Pobiega•8mo ago
since Length is a property, not a method, thats not available
LPeter1997
LPeter1997•8mo ago
Count :trollface:
Lvgraef
LvgraefOP•8mo ago
i thought it was a method how do i even see if its a method or a property
Pobiega
Pobiega•8mo ago
by using your eyes
Lvgraef
LvgraefOP•8mo ago
i hate the c# naming conventions
Pobiega
Pobiega•8mo ago
🙂
Lvgraef
LvgraefOP•8mo ago
i dont see the source tho
Pobiega
Pobiega•8mo ago
No description
Lvgraef
LvgraefOP•8mo ago
it looks exactly the same as a method
LPeter1997
LPeter1997•8mo ago
No description
Lvgraef
LvgraefOP•8mo ago
ye i dont see that so there is no way to write this shorter then?
Pobiega
Pobiega•8mo ago
no also.. why? x => x isnt that long
Lvgraef
LvgraefOP•8mo ago
its ugly
Pobiega
Pobiega•8mo ago
its important
sibber
sibber•8mo ago
you dont have intellisense?
LPeter1997
LPeter1997•8mo ago
You can technically write Enumerable.Count, does have some overhead but should not actually iterate the entire str. Also I'd never do that...
Lvgraef
LvgraefOP•8mo ago
idk my rider seems to not work rn
Pobiega
Pobiega•8mo ago
then fix your rider coding without intellisense is just making your life harder for no reason
LPeter1997
LPeter1997•8mo ago
No description
LPeter1997
LPeter1997•8mo ago
Idk... I'd just write the latter
Lvgraef
LvgraefOP•8mo ago
ye i know i will fix it well its fine i jsut thought there would be the shorter way of writing it
Pobiega
Pobiega•8mo ago
embrace the lambda. learn to love it
LPeter1997
LPeter1997•8mo ago
You can also write your own method if you write it that many times... Like
static int Length(string s) => s.Length;
static int Length(string s) => s.Length;
But generally only if this is local to a class of yours or something, definitely do not put this in some shared context, that's confusing and Pythonic af
Jimmacle
Jimmacle•8mo ago
invalidate caches and restart, that tends to fix the editor being drunk for me

Did you find this page helpful?