in Technology by
How to return multiple types without out and ref parameter in C#?

1 Answer

0 votes
by
(string, string, string) LookupName(long id) // tuple return type { ... // retrieve first, middle and last from data storage return (first, middle, last); // tuple literal }

which could then be used like this:

var names = LookupName(id); WriteLine($"found {names.Item1} {names.Item3}.");

You can also provide names to your elements (so they are not "Item1", "Item2" etc). You can do it by adding a name to the signature or the return methods:

(string first, string middle, string last) LookupName(long id) // tuple elements have names

or

return (first: first, middle: middle, last: last); // named tuple elements in a literal

They can also be deconstructed, which is a pretty nice new feature:

(string first, string middle, string last) = LookupName(id1); // deconstructing declaration

Related questions

0 votes
    What is the difference between ref and out keywords?...
asked Mar 31, 2021 in Technology by JackTerrance
0 votes
    I have a function value(x) which is overloaded for many types such that: double value(double x) { return x; } double ... [-Wreturn-local-addr] in the following code: Matrix33 m; m...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Using which attribute we can add a tooltip in the HTML element. 1. tooltip 2. title 3. ref 4. None of the above...
asked Jul 12, 2021 in Technology by JackTerrance
0 votes
    I haven't been able to find this explicitly stated anywhere yet, but a bunch of examples I've ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    How to Catch multiple exceptions at once in C#?...
asked Jan 15, 2021 in Technology by JackTerrance
0 votes
    Can a function return multiple values to the caller using return reserved word in C?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    perimeter of circle in c program without argument with return type Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    How you can implement nullable types in C#? explain with the syntax of Nullable type....
asked Jul 27, 2021 in Technology by JackTerrance
0 votes
    The strategy used to ensure that the message is a multiple of the cipher block size without compromising the size ... 1)Ciphertext stealing (2)Padding (3)Refactoring (4)Diffusion...
asked Mar 19, 2021 in Technology by JackTerrance
0 votes
    A single ______________ further allows the user to be authenticated once, and multiple applications can then ... in chapter Database Programming Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    What are the main return types supported in dotnet WEB API?...
asked Aug 10, 2021 in Technology by JackTerrance
0 votes
    What are the different return types used by the controller action method in MVC?...
asked Dec 8, 2020 in Technology by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What do you mean by value types and reference types in C#?...
asked Jul 27, 2021 in Technology by JackTerrance
...