Browsing 7239 questions and answers with Jon Skeet
containsValue has to iterate over all the entries in the hash table anyway - so just change your code so that you do that: for (Map.Entry<Integer, String> entry : hashtable) { if (word.equals(entry.getValue()) { // Use... more 1/31/2018 10:43:55 AM
I suspect you just happened to run at an instant where the time was on a 10ms boundary on the Mac. Here's some sample code to try: import java.time.*; import java.time.format.*; class Test { public static void main(String[] args)... more 1/31/2018 10:18:42 AM
Just do it in three statements instead of two, using a local variable: var list = obj.stuckArray.ToList(); list.RemoveAt(1); obj.stuckArray = list; That way the type of stuckArray doesn't matter as much: you only need to be able to call... more 1/30/2018 5:04:00 PM
Yes, there's fairly simple way around it, at least in this case: create a static method which will prepare the constructor argument for you. Call that from the this expression: public YahtzeeGame(int numberOfPlayers) { ... more 1/30/2018 3:38:52 PM
Basically, the Calendar API is horrible, and should be avoided. It's not documented terribly clearly, but I think I see where it's going, and it's behaving as intended in this situation. By that I mean it's following the intention of the... more 1/30/2018 10:31:10 AM
How does the compiler know that I can't use SystemDefault on .NET 4.5 but can use it on 4.7? Is this done via some kind of API file known to the compiler? Yes, I'd expect it to be done via the reference assemblies. A reference... more 1/29/2018 2:43:58 PM
The example you gave is a reasonably easy one - but there are harder ones. Consider this: Date of birth: Feb 29th 1976 Event date: Feb 28th 1994 If you add 18 years to the date of birth, you'll get Feb 28th 1994 - the event date. That... more 1/29/2018 11:17:01 AM
It sounds to me like you want to group by eligibility, then order those groups by their key (descending), then take the first group: var bestSpawnGroup = _spawns .GroupBy(GetEligibility) .OrderByDescending(g => g.Key) ... more 1/28/2018 9:09:09 AM
You can't read from the stream twice. After this call: responseStream.CopyTo(output); ... you've already read all the data in the stream. There's nothing left to read, and you can't "rewind" the stream (e.g. seeking to the beginning)... more 1/28/2018 7:51:20 AM
This is a slightly more efficient version of felix-b's answer - it doesn't require creating a new list. It will return as soon as it's sure of the result, without any need for checking the rest of the elements. string... more 1/27/2018 9:28:29 AM