Browsing 7239 questions and answers with Jon Skeet
Sure - that's just a projection from each element of the index: List<double> val = index.Select(i => dSet[0, i]).ToList(); Any time you've got something along the lines of "for each element from source, do something to get an... more 6/11/2014 6:07:29 AM
Replace is used to replace one character or string within a string with another. For example, "mum".Replace("u", "o") will return "mom". That's not counting occurrences of anything - it's not the method you want at all. It sounds like you... more 6/11/2014 5:49:10 AM
You're using foreach on a string. Effectively: string x = "foo"; foreach (string y in x) That makes no sense - a string is a sequence of characters, not a sequence of strings. In order to get the code to compile, you could just remove... more 6/10/2014 6:47:13 PM
It seems like whatever changes we made to element in NewArray, MyArray will change along, why? You aren't changing NewArray. You're changing the array that the value of NewArray refers to. It's like this: NewArray is a variable (an... more 6/10/2014 5:26:54 PM
Just to answer one part: List<T> has its own enumerator implementation for two reasons: It can't just return the iterator of its backing array, because: It needs to detect structural changes in the list (additions and removals)... more 6/10/2014 3:45:02 PM
The code you've given has two problems: Optional parameters must come last (apart from params parameters) const fields must be assigned compile-time constants, and string.Empty isn't a const field Because Empty isn't a valid const, your... more 6/10/2014 3:31:45 PM
That's precisely what the source of the ActionEvent is for: public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); System.out.println("Event triggered by " + button.getText()); } more 6/10/2014 12:28:49 PM
You can use [@att] to test for the presence of an attribute, so you just need: //elem[not(@att)] ... to test for the absence of it. (Tested using xpathtester) more 6/10/2014 12:22:03 PM
It is evaluating both conditions - but as soon as the condition is false, the rest of the sequence is returned. As soon as n==2, n < 2 && n != 2 is false. In fact, your condition makes no sense anyway - if n is less than 2 it... more 6/10/2014 11:13:23 AM
Your type variable is a String, but you're trying to specify values which are CoffeeSort values. You'll need to convert the String to a CoffeeSort first, or change the signature. For example: public ACoffee createCoffee(CoffeeSort type)... more 6/10/2014 10:42:06 AM