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

C#

 
QuestionRe: how do I get the information from a site of a button? Pin
CHill6023-Apr-16 5:15
mveCHill6023-Apr-16 5:15 
AnswerRe: how do I get the information from a site of a button? Pin
Member 1248006323-Apr-16 5:28
Member 1248006323-Apr-16 5:28 
AnswerRe: how do I get the information from a site of a button? Pin
OriginalGriff23-Apr-16 5:30
mveOriginalGriff23-Apr-16 5:30 
GeneralRe: how do I get the information from a site of a button? Pin
Member 1248006323-Apr-16 5:35
Member 1248006323-Apr-16 5:35 
GeneralRe: how do I get the information from a site of a button? Pin
CHill6023-Apr-16 5:38
mveCHill6023-Apr-16 5:38 
GeneralRe: how do I get the information from a site of a button? Pin
OriginalGriff23-Apr-16 5:44
mveOriginalGriff23-Apr-16 5:44 
GeneralRe: how do I get the information from a site of a button? Pin
Member 1248006323-Apr-16 5:46
Member 1248006323-Apr-16 5:46 
Questionc# complex dictionary: can modify value in for-loop: thought you couldn't do that Pin
BillWoodruff23-Apr-16 0:10
professionalBillWoodruff23-Apr-16 0:10 
I don't know which is better, or worse, having code that works for reasons you don't understand, or having code that breaks for reasons you don't understand Smile | :)

Today I was testing the use of a complex dictionary of the form:
C#
public Dictionary<KeyValuePair<T1,T2>, List<T3>>
I was surprised to find that I could iterate ... in a lambda expression passed as the argument to a Func ... over the List of T3 with a 'for loop and change the values without getting the "attempt to modify ..." error. Example:
C#
Test = new Dictionary<KeyValuePair<string, int>, List<int>>
{
   {new KeyValuePair<string,int>("hello",1),
    new List<int> {1,2,3,4}},

   {new KeyValuePair<string,int>("goodbye",2),
    new List<int> {6,7,8,9}}
};

foreach (var kvp in Test)
{
    for (int i = 0; i < kvp.Value.Count; i++)
    {
        kvp.Value[i] *= 10;
    }
}
Of course, you can never change the value of the Key or Value of the KeyValuePair ... they have no setters, but, I was surprised I could modify the value in this kind of loop ... I assume I could always modify the value outside of a loop where I iterated across the structure.

So, why don't this break ? My memory includes the use of various yogic contortions a few years ago to avoid the "can't modify collection" error.

Come to think on it: I distrust code that works for reasons I don't understand more than ... the other Smile | :)

thanks, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

AnswerRe: c# complex dictionary: can modify value in for-loop: thought you couldn't do that Pin
OriginalGriff23-Apr-16 0:24
mveOriginalGriff23-Apr-16 0:24 
GeneralRe: c# complex dictionary: can modify value in for-loop: thought you couldn't do that Pin
BillWoodruff23-Apr-16 2:20
professionalBillWoodruff23-Apr-16 2:20 
GeneralOT: Our mutually increasing decrepitude Pin
OriginalGriff23-Apr-16 2:29
mveOriginalGriff23-Apr-16 2:29 
GeneralRe: c# complex dictionary: can modify value in for-loop: thought you couldn't do that Pin
Richard Deeming23-Apr-16 3:39
mveRichard Deeming23-Apr-16 3:39 
QuestionHow to wait to execute for next process till current process complete using C# Process Object Pin
Tej_dev22-Apr-16 5:32
Tej_dev22-Apr-16 5:32 
AnswerRe: How to wait to execute for next process till current process complete using C# Process Object Pin
Richard Deeming22-Apr-16 5:44
mveRichard Deeming22-Apr-16 5:44 
GeneralRe: How to wait to execute for next process till current process complete using C# Process Object Pin
Tej_dev22-Apr-16 6:11
Tej_dev22-Apr-16 6:11 
GeneralRe: How to wait to execute for next process till current process complete using C# Process Object Pin
Tej_dev28-Apr-16 8:56
Tej_dev28-Apr-16 8:56 
GeneralRe: How to wait to execute for next process till current process complete using C# Process Object Pin
Richard Deeming28-Apr-16 9:04
mveRichard Deeming28-Apr-16 9:04 
QuestionC# TableAdapter - Oracle with Identity/Sequence -Column Pin
gpc4421-Apr-16 4:01
gpc4421-Apr-16 4:01 
AnswerRe: C# TableAdapter - Oracle with Identity/Sequence -Column Pin
Dave Kreskowiak21-Apr-16 5:59
mveDave Kreskowiak21-Apr-16 5:59 
QuestionConvert code .Net4.0 to code .Net 2.0 Pin
Member 245846720-Apr-16 17:19
Member 245846720-Apr-16 17:19 
QuestionRe: Convert code .Net4.0 to code .Net 2.0 Pin
DanielBrownAU20-Apr-16 17:48
professionalDanielBrownAU20-Apr-16 17:48 
AnswerRe: Convert code .Net4.0 to code .Net 2.0 Pin
Simon_Whale21-Apr-16 0:57
Simon_Whale21-Apr-16 0:57 
GeneralRe: Convert code .Net4.0 to code .Net 2.0 Pin
Member 245846721-Apr-16 2:42
Member 245846721-Apr-16 2:42 
GeneralRe: Convert code .Net4.0 to code .Net 2.0 Pin
Dave Kreskowiak21-Apr-16 3:34
mveDave Kreskowiak21-Apr-16 3:34 
GeneralRe: Convert code .Net4.0 to code .Net 2.0 Pin
Member 245846721-Apr-16 13:19
Member 245846721-Apr-16 13:19 

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.