DEV Community

Ola Johansson
Ola Johansson

Posted on

My Tuples in C# note to self

Everytime i just temporary need to send some data from one method to another i'm running into the issue, "I don't want to create a class just for this, can't just send some anonymous method of some sort".

And each time I'm struggling with Tuples. The worst thing is that it's so hard to search for "where i used it before" since it doesn't really have name to search for.

And that is why i'm writing this now.

var myListOfTuple = row.SomeTable
    .Select(o => new { o.UserId, o.User.Number, o.User.AnotherNumber })
    .AsEnumerable() 
    .Select(o => (UserId: o.UserId, Number: o.Number, AnotherNumber: o.AnotherNumber))
    .ToList();

DoStuff(myListOfTuple);

public int DoStuff(List<(Guid userId, int Points, int SecurityLevel)> myTupleList) {

var things = myTupleList.Where(x => x.Number > 5 && x.UserId != 1234);

}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay