How to check items in a Collection contains common property?
-
Is there any better way in c# to check items in a collection contains common property besides looping through with a flag and finding out? say for example, a text item collection contains fontweight bold for all text item
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Not really. You may be able to do it with Linq, but how to do that will depend on the items you are talking about.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
Not really. You may be able to do it with Linq, but how to do that will depend on the items you are talking about.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
trying to do something like this
textBold.Checked = true;
foreach (Item item in Items)
{
if (item.FontWeight == FontWeights.Normal)
{
textBold.Checked = false;
}
}but FontWeights include more values
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
-
trying to do something like this
textBold.Checked = true;
foreach (Item item in Items)
{
if (item.FontWeight == FontWeights.Normal)
{
textBold.Checked = false;
}
}but FontWeights include more values
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Add a
break
: textBold.Checked = true;foreach (Item item in Items)
{
if (item.FontWeight == FontWeights.Normal)
{
textBold.Checked = false;
break;
}
}As I said, you could do it with Linq:
int normal = Items.Count(item => item.FontWeight == FontWeights.Normal);
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
Is there any better way in c# to check items in a collection contains common property besides looping through with a flag and finding out? say for example, a text item collection contains fontweight bold for all text item
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Now the solution doesn't make much sense because you've removed a link in the chain. Other people might have found this useful, but you've made it hard for them. Never, ever, remove a message that's been replied to.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Now the solution doesn't make much sense because you've removed a link in the chain. Other people might have found this useful, but you've made it hard for them. Never, ever, remove a message that's been replied to.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
I agree, however IMO you're asking the wrong person. It is Chris who simply shouldn't present a "Delete" widget for messages that have replies. I have asked him many times, he eventually fixed half of it (the top level message). :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I agree, however IMO you're asking the wrong person. It is Chris who simply shouldn't present a "Delete" widget for messages that have replies. I have asked him many times, he eventually fixed half of it (the top level message). :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
I know. I was going to post a request and then thought, what's the point - it's been asked for before and still isn't here.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Now the solution doesn't make much sense because you've removed a link in the chain. Other people might have found this useful, but you've made it hard for them. Never, ever, remove a message that's been replied to.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Add a
break
: textBold.Checked = true;foreach (Item item in Items)
{
if (item.FontWeight == FontWeights.Normal)
{
textBold.Checked = false;
break;
}
}As I said, you could do it with Linq:
int normal = Items.Count(item => item.FontWeight == FontWeights.Normal);
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
I agree, however IMO you're asking the wrong person. It is Chris who simply shouldn't present a "Delete" widget for messages that have replies. I have asked him many times, he eventually fixed half of it (the top level message). :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
I've asked for it on Q&A as well a few times - it really annoys me when you answer a question and it gets deleted because they (presumably) don't want the answer to help anyone else...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
I've asked for it on Q&A as well a few times - it really annoys me when you answer a question and it gets deleted because they (presumably) don't want the answer to help anyone else...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
I remember some sites where it was expected to remove a problem once it got solved. CP however doesn't expect that; it does offer a "Delete" widget, and when used, you're bound to get "don't do that" comments. Pretty confusing if you ask me. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I remember some sites where it was expected to remove a problem once it got solved. CP however doesn't expect that; it does offer a "Delete" widget, and when used, you're bound to get "don't do that" comments. Pretty confusing if you ask me. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Yes, and I have no problem with it's existence. If you post a stupid question, and that makes you realise just how dumb you have been, then deleting it before anyone notices or answers is fine by me. But, when it is a complicated answer that can take half an hour to get right, and the OP deletes it as soon as he reads it, that does annoy me, I admit. If nothing else, it doesn't appear in any list I can access to copy it or refer anyone else to next time...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."