Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Genericize access to variables Pin
Luc Pattyn1-Sep-10 5:12
sitebuilderLuc Pattyn1-Sep-10 5:12 
GeneralRe: Genericize access to variables Pin
Chris Trelawny-Ross1-Sep-10 5:19
Chris Trelawny-Ross1-Sep-10 5:19 
AnswerRe: Genericize access to variables Pin
#realJSOP1-Sep-10 5:21
mve#realJSOP1-Sep-10 5:21 
GeneralRe: Genericize access to variables Pin
Ian Shlasko1-Sep-10 5:25
Ian Shlasko1-Sep-10 5:25 
AnswerRe: Genericize access to variables PinPopular
The Man from U.N.C.L.E.1-Sep-10 7:05
The Man from U.N.C.L.E.1-Sep-10 7:05 
AnswerRe: Genericize access to variables Pin
Eddy Vluggen1-Sep-10 7:42
professionalEddy Vluggen1-Sep-10 7:42 
AnswerRe: Genericize access to variables Pin
BC3Tech2-Sep-10 3:10
BC3Tech2-Sep-10 3:10 
GeneralRe: Genericize access to variables Pin
Eddy Vluggen2-Sep-10 8:45
professionalEddy Vluggen2-Sep-10 8:45 
Lambda's look cool Cool | :cool:

It's either searching through the collection and keeping the result around, or hardcoding them in advance. Attributes that mark a set of fields as a group might be another option, but that would add a bit more complexity.

No, I think I like the lambda better. Would also be cool combined with a regex Smile | :)

Nearly forgot, but that cast in my original query would be redundant, as we'd only need to store labels;
C#
class Form1
{
    IEnumerable<Label> summingLabels; 
    public Form1()
    {
    	InitializeComponent();
	
    	summingLabels =
    		from c in Controls.Cast<Control>().AsQueryable()
    		where c.GetType() == typeof(Label)
    		&& c.Name.StartsWith("label")
    		select c as Label;
    
    	// later on, when you need them
    	foreach(Label l in summingLabels)
    		l.Text = l.Location.ToString();
    }
}

I are Troll Suspicious | :suss:

GeneralRe: Genericize access to variables Pin
Shani Natav2-Sep-10 9:14
Shani Natav2-Sep-10 9:14 
GeneralRe: Genericize access to variables Pin
Eddy Vluggen2-Sep-10 9:22
professionalEddy Vluggen2-Sep-10 9:22 
AnswerRe: Genericize access to variables PinPopular
Daniel Grunwald1-Sep-10 8:20
Daniel Grunwald1-Sep-10 8:20 
GeneralRe: Genericize access to variables Pin
PIEBALDconsult1-Sep-10 9:04
mvePIEBALDconsult1-Sep-10 9:04 
AnswerRe: Genericize access to variables [modified] Pin
Paul Michalik1-Sep-10 11:47
Paul Michalik1-Sep-10 11:47 
GeneralRe: Genericize access to variables Pin
AspDotNetDev1-Sep-10 11:51
protectorAspDotNetDev1-Sep-10 11:51 
AnswerRe: Genericize access to variables Pin
Łukasz Nowakowski1-Sep-10 20:14
Łukasz Nowakowski1-Sep-10 20:14 
AnswerRe: Genericize access to variables Pin
Alexander Voronin2-Sep-10 1:52
Alexander Voronin2-Sep-10 1:52 
AnswerRe: Genericize access to variables Pin
ExportedNorwegian2-Sep-10 2:01
ExportedNorwegian2-Sep-10 2:01 
AnswerRe: Genericize access to variables Pin
Dave Buhl2-Sep-10 3:11
Dave Buhl2-Sep-10 3:11 
AnswerRe: Genericize access to variables Pin
JaceTheAce2-Sep-10 4:12
JaceTheAce2-Sep-10 4:12 
AnswerRe: Genericize access to variables Pin
RMcEachern2-Sep-10 10:37
RMcEachern2-Sep-10 10:37 
AnswerRe: Genericize access to variables Pin
coolguy19882-Sep-10 15:09
coolguy19882-Sep-10 15:09 
QuestionDo you know which office outlook 2003 component can be sign into Microsoft Exchange Server via outlook? Pin
milestanley1-Sep-10 1:44
milestanley1-Sep-10 1:44 
Questionquestion Pin
bitayekta1-Sep-10 0:51
bitayekta1-Sep-10 0:51 
AnswerRe: question Pin
Pete O'Hanlon1-Sep-10 1:05
mvePete O'Hanlon1-Sep-10 1:05 
AnswerRe: question Pin
Smithers-Jones1-Sep-10 5:12
Smithers-Jones1-Sep-10 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.