Browsing 7239 questions and answers with Jon Skeet

Lambda parameter conflicting with class field on accessing field in later scope

I've got a weak imagination when it comes to names, so I often find myself re-using identifiers in my code. This caused me to run into this specific problem. Here's some example...
Jon Skeet
people
quotationmark

I raised Roslyn issue 2110 for this - the C# 6 spec is changing to allow this. Mads Torgersen has indicated that the change is by design: The rule was well intended, in that it was supposed to minimize the risk of "moving code around"... more 4/20/2015 5:18:23 PM

people

Can a double initialized with a small whole number value be used with accuracy in a BigDecimal context?

It is well documented that using a double can lead to inaccuracies and that BigDecimal guarantees accuracy so long as there are no doubles in the mix. However, is accuracy...
Jon Skeet
people
quotationmark

The BigDecimal aspect isn't as relevant to this question as "what is the range of integers that can be exactly represented in double?" - in that every finite double value can be represented exactly by BigDecimal, and that's the value... more 4/20/2015 1:43:39 PM

people

Index out of bounds when create new thread with parameters?

I'm working on my project about Bakery Algorithm but i don't have any demo of that Algorithm in C# . Because of that situation i've converted some java code that i found on...
Jon Skeet
people
quotationmark

This is the problem: threadArray[i] = new Thread(() => simThread(i)); You're capturing i here - the single variable which will be updated over the course of the loop, and end up with a value of threads. If the thread only actually... more 4/20/2015 10:29:39 AM

people

Java Collection Using Date Sorting on Same Date with AM/PM

I have Date as listed below: 17/03/2015 09:38:39 AM 17/03/2015 10:52:26 AM 10/03/2015 08:30:56 AM 02/03/2015 09:18:10 AM 02/03/2015 09:37:23 AM 02/03/2015 11:25:01 AM 02/03/2015...
Jon Skeet
people
quotationmark

The core problem IMO is that you don't have a collection of dates - you have a collection of strings. I would recommend parsing those strings into a more suitable data type - I'd use LocalDateTime in either java.time or Joda Time if you... more 4/20/2015 6:05:37 AM

people

Adding two ints not doing anything

So the problem is, when I say ovrxp = ovrxp + xp, it never stacks and just resets every kill. A fix to this and an explanation to why this doesn't work would be much appreciated....
Jon Skeet
people
quotationmark

You've declared ovrxp as a local variable - it's initialized each time onDeath is called. If you want the value to persist between multiple calls to the method, you'll need to make the variable a field (part of the object itself).... more 4/19/2015 9:10:31 PM

people

Convert DateTime from specific time zone to UTC using Nodatime?

Ok, So I have a web server that is hosted in the Central Standard Time Zone. The IIS server is configured with that as the Time Zone, so whenever use DateTime.Now on the server...
Jon Skeet
people
quotationmark

What I am confused about is how to create a Nodatime variable for a specific time zone at a specific date/time? That's relatively easy: LocalDateTime local = new LocalDateTime(2015, 4, 17, 8, 0, 0); DateTimeZone zone =... more 4/17/2015 8:04:16 PM

people

Java How To Find Class? (Attempting to load the driver: com.mysql.jdbc.Driver)

I am trying to use adit in my local environment. I copied the files to: /Users/koraytugay/adit-0.93 I go to terminal and type: export...
Jon Skeet
people
quotationmark

When you use -jar, the CLASSPATH environment variable is ignored. The simplest approach here would probably be to use: java -cp adit.jar:/Users/koraytugay/adit-0.93/mysql-connector-java-5.1.33.jar foo.bar.MyMainClass Alternatively,... more 4/17/2015 12:30:25 PM

people

Difference between static modifier and static block

Someone explain to me the differences between the following two statements? A static final variable initialized by a static code block: private static final String foo; static {...
Jon Skeet
people
quotationmark

In this example, there's one subtle difference - in your first example, foo isn't determined to be a compile-time constant, so it can't be used as a case in switch blocks (and wouldn't be inlined into other code); in your second example... more 4/17/2015 6:07:24 AM

people

Write a program that prompts the user to input a sequence of characters and outputs the numbers of vowels

import java.util.*; public class VowelCounter { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Input a...
Jon Skeet
people
quotationmark

This is your problem: String letters = keyboard.next(); It has nothing to do with the vowel-counting part - but everything to do with reading the value. The Scanner.next() method will only read to the end of the token - which means it... more 4/16/2015 4:45:41 PM

people

how to convert "value" to enum?

I have this enum class: public enum IconImageTag { None("val1"), USD("val2"), EURO("val3"); } given a string which represent a "value" (say `"val"1) how can I...
Jon Skeet
people
quotationmark

Ideally, you'd build up a Map<String, IconImageTag> and add an appropriate method. For example: public enum IconImageTag { NONE("val1"), USD("val2"), EURO("val3"); private final String value; private final... more 4/16/2015 2:00:05 PM

people