11,641,971 members (62,548 online)

# C#

 Re: cue banner not working Wes Aday17-Aug-12 8:28 Wes Aday 17-Aug-12 8:28
 Re: cue banner not working Richard Andrew x6417-Aug-12 8:18 Richard Andrew x64 17-Aug-12 8:18
 Tuples in Functions computerpublic17-Aug-12 3:52 computerpublic 17-Aug-12 3:52
 Re: Tuples in Functions Wayne Gaylard17-Aug-12 4:37 Wayne Gaylard 17-Aug-12 4:37
 Re: Tuples in Functions harold aptroot17-Aug-12 8:16 harold aptroot 17-Aug-12 8:16
 Re: Tuples in Functions Ravi Bhavnani17-Aug-12 4:39 Ravi Bhavnani 17-Aug-12 4:39
 Re: Tuples in Functions DaveyM6917-Aug-12 22:21 DaveyM69 17-Aug-12 22:21
 Re: Tuples in Functions BillWoodruff18-Aug-12 7:17 BillWoodruff 18-Aug-12 7:17
 Re: Tuples in Functions DaveyM6918-Aug-12 8:09 DaveyM69 18-Aug-12 8:09
 Re: Tuples in Functions Meysam Tolouee18-Aug-12 5:20 Meysam Tolouee 18-Aug-12 5:20
 Re: Tuples in Functions DaveyM6918-Aug-12 8:15 DaveyM69 18-Aug-12 8:15
 Re: Tuples in Functions Meysam Tolouee18-Aug-12 9:53 Meysam Tolouee 18-Aug-12 9:53
 Re: Tuples in Functions Keith Barrow18-Aug-12 9:38 Keith Barrow 18-Aug-12 9:38
 Re: Tuples in Functions BillWoodruff18-Aug-12 9:43 BillWoodruff 18-Aug-12 9:43
 Between the responses to your first post, the responses to this post, and the (strangely out of place) discussion on the Lounge[^], you have a of ideas, and alternate strategies for using Tuples. I want to respond directly to your question about using Tuples. In my opinion, they can best be described as a "bag of pairs" where, for every pair in the bag: the first element, of the pair, is a Type; and, the second element is a value of that Type. And, do keep in mind that Tuples were introduced in .NET 4.0. So, they are most appropriate, imho, if you need to return a bunch of different types: if every Type in your Tuple elements is the same: then use one of the other strategies, or a generic List, or another method. Let me try and make this concrete for you: you can download this project (with source) compiled against .NET 4.0 here:[^]. 1. create a simple 'WinForms application: drop a 'CheckBox, a 'DateTimePicker, a 'TextBox, and a 'NumericUpDown[1] on the main Form. 2. put two 'Buttons on the Form: title the first 'Button "Save Tuple," and the second "Restore Tuple." Now let's look at what happens using a real Tuple in action: (attention: code-style obsessive-compulsives: I am using extra indentation, and line-breaks, here for clarity for the OP, it would not be my standard style): 1. first you declare a Form-scoped variable of Type Tuple for re-use:`private Tuple _fourTuple;`1. You run the application, change the values of any of the four controls any way you like, and click the "Save Tuple" button: this code executes:```private void SaveTupleButtonClick(object sender, EventArgs e) { _fourTuple = Tuple.Create ( checkBox1.CheckState, dateTimePicker1.Value, textBox1.Text, numericUpDown1.Value ); }```Here I am using the static Tuple.Create method, which was introduced in .NET FrameWork 4.0, to save some typing; it's exactly the same as if I wrote the fuller version:```private void SaveTupleButton_Click(object sender, EventArgs e) { _fourTuple = new Tuple ( checkBox1.CheckState, dateTimePicker1.Value, textBox1.Text, numericUpDown1.Value ); }```And now: what ? Well, you've saved the current values of these diverse types of Controls in your tuple. So, go ahead and change the values of all the Controls, and hit the "Restore Tuple" 'Button:```private void RestoreTupleClick(object sender, EventArgs e) { checkBox1.CheckState = _fourTuple.Item1; dateTimePicker1.Value = _fourTuple.Item2; textBox1.Text = _fourTuple.Item3; numericUpDown1.Value = _fourTuple.Item4; }```I hope you will see the controls' values reset to the exact value they were: when you pressed the "Save Tuple" 'Button. Hope this example gives you some ideas. best, Bill [1] Keep in mind that 'NumericUpDownControls have 'Minimum and 'Maximum value settings, as well as a 'DecimalPlaces property: if you type in a value out of range: it will revert to the nearest min or max value: this can have a confusing run-time effect for the end user. "One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut
 My Vote of 5 Keith Barrow18-Aug-12 10:32 Keith Barrow 18-Aug-12 10:32
 Re: Tuples in Functions `leppie`18-Aug-12 21:37 `leppie` 18-Aug-12 21:37
 Re: Tuples in Functions BillWoodruff19-Aug-12 14:15 BillWoodruff 19-Aug-12 14:15
 Re: Tuples in Functions `leppie`19-Aug-12 19:41 `leppie` 19-Aug-12 19:41
 Leppie's interesting suggestion to use 'Anonymous Classes' ... Re: Tuples in Functions BillWoodruff18-Aug-12 15:49 BillWoodruff 18-Aug-12 15:49
 Re: Leppie's interesting suggestion to use 'Anonymous Classes' ... Re: Tuples in Functions BobJanova20-Aug-12 1:00 BobJanova 20-Aug-12 1:00
 Trying to Obtain Two (2) Values from Function computerpublic16-Aug-12 21:53 computerpublic 16-Aug-12 21:53
 Re: Trying to Obtain Two (2) Values from Function DaveyM6916-Aug-12 22:36 DaveyM69 16-Aug-12 22:36
 Re: Trying to Obtain Two (2) Values from Function BobJanova16-Aug-12 22:54 BobJanova 16-Aug-12 22:54
 Re: Trying to Obtain Two (2) Values from Function Keith Barrow17-Aug-12 2:12 Keith Barrow 17-Aug-12 2:12
 Re: Trying to Obtain Two (2) Values from Function Sangramsingh Pawar17-Aug-12 0:43 Sangramsingh Pawar 17-Aug-12 0:43
 Re: Trying to Obtain Two (2) Values from Function V.17-Aug-12 3:16 V. 17-Aug-12 3:16
 Re: Trying to Obtain Two (2) Values from Function Kuthuparakkal17-Aug-12 16:05 Kuthuparakkal 17-Aug-12 16:05
 How to insert,update and edit data in datagridview window form Member 912701916-Aug-12 19:54 Member 9127019 16-Aug-12 19:54
 Re: How to insert,update and edit data in datagridview window form Calla16-Aug-12 20:53 Calla 16-Aug-12 20:53
 Re: How to insert,update and edit data in datagridview window form Dave Kreskowiak17-Aug-12 3:37 Dave Kreskowiak 17-Aug-12 3:37
 Re: How to insert,update and edit data in datagridview window form Uma Shankar Patel17-Aug-12 21:52 Uma Shankar Patel 17-Aug-12 21:52
 Is it possible to read windows password from registry? Mostafa M.A16-Aug-12 15:09 Mostafa M.A 16-Aug-12 15:09
 Re: Is it possible to read windows password from registry? Eddy Vluggen16-Aug-12 15:31 Eddy Vluggen 16-Aug-12 15:31
 Re: Is it possible to read windows password from registry? Mostafa M.A16-Aug-12 16:20 Mostafa M.A 16-Aug-12 16:20
 Re: Is it possible to read windows password from registry? Eddy Vluggen16-Aug-12 16:31 Eddy Vluggen 16-Aug-12 16:31
 Message Removed Kuthuparakkal16-Aug-12 18:35 Kuthuparakkal 16-Aug-12 18:35
 Re: Is it possible to read windows password from registry? Eddy Vluggen16-Aug-12 23:35 Eddy Vluggen 16-Aug-12 23:35
 Message Removed Kuthuparakkal17-Aug-12 2:12 Kuthuparakkal 17-Aug-12 2:12
 Re: Is it possible to read windows password from registry? Eddy Vluggen17-Aug-12 2:49 Eddy Vluggen 17-Aug-12 2:49
 Re: Is it possible to read windows password from registry? Dave Kreskowiak17-Aug-12 3:36 Dave Kreskowiak 17-Aug-12 3:36
 Re: Is it possible to read windows password from registry? harold aptroot17-Aug-12 3:41 harold aptroot 17-Aug-12 3:41
 What is this C# console compile error and how do I fix it? Xarzu16-Aug-12 11:03 Xarzu 16-Aug-12 11:03
 Re: What is this C# console compile error and how do I fix it? jschell16-Aug-12 11:05 jschell 16-Aug-12 11:05
 Re: What is this C# console compile error and how do I fix it? Xarzu16-Aug-12 11:19 Xarzu 16-Aug-12 11:19
 Re: What is this C# console compile error and how do I fix it? Wes Aday16-Aug-12 11:31 Wes Aday 16-Aug-12 11:31
 Re: What is this C# console compile error and how do I fix it? Eddy Vluggen16-Aug-12 13:29 Eddy Vluggen 16-Aug-12 13:29
 Re: What is this C# console compile error and how do I fix it? Eddy Vluggen16-Aug-12 13:31 Eddy Vluggen 16-Aug-12 13:31
 Re: What is this C# console compile error and how do I fix it? Bernhard Hiller16-Aug-12 21:19 Bernhard Hiller 16-Aug-12 21:19
 Re: What is this C# console compile error and how do I fix it? OriginalGriff16-Aug-12 21:38 OriginalGriff 16-Aug-12 21:38
 Re: What is this C# console compile error and how do I fix it? OriginalGriff16-Aug-12 21:23 OriginalGriff 16-Aug-12 21:23
 Last Visit: 31-Dec-99 18:00     Last Update: 2-Aug-15 3:06 Refresh « Prev1...516517518519520521522523524525 Next »