what is tuple in mvc
-
which one is use tuple or out varaible . which is best?
-
which one is use tuple or out varaible . which is best?
If you are unsure about what a tuple is, I wrote a brief guide for Pluralsight last year, https://www.pluralsight.com/guides/returning-consuming-tuples[^]. Something to consider if you use async/await, you can't use out with your parameters but you can return a tuple as part of the Task signature.
-
which one is use tuple or out varaible . which is best?
If one were "best", there's no reason to keep it around in the framework. You can also use tuples as out variables, which makes your question unclear to me. Can you give us two examples of what you are trying to compare?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
If one were "best", there's no reason to keep it around in the framework. You can also use tuples as out variables, which makes your question unclear to me. Can you give us two examples of what you are trying to compare?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
So Tuple is a good thing. It is very useful in scenarios where you need to return multiple values from a method but do not intend to create a dedicated DTO for that sole purpose. It is not of structure type either which means it is passed by reference. I created 2 methods in my controller for testing Tuple - one for Get and other for Post.
[HttpGet]
public ActionResult TestTuple()
{
Tuple t = new Tuple("test", 123);
return View(t);
}\[HttpPost\] public ActionResult TestTuple(Tuple tuple) { return new EmptyResult(); }
The view part is straightforward:
@model Tuple
@{
ViewBag.Title = "TestTuple";
}@Html.BeginForm("TestTuple", "Home", FormMethod.Post){
@Html.EditorFor(m => m); input type="submit" value="Test Tuple"/
}