Browsing 7239 questions and answers with Jon Skeet

Why is it possible for objects to change the value of class variables?

By Oracle's definition, Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static...
Jon Skeet
people
quotationmark

It's not really that "one object" can - it's just you're in code which has access to that variable, and unfortunately Java allows you to access static members (both variables and methods) as if they were instance members. This ends up with... more 3/14/2015 3:15:21 PM

people

PHP DateTime converting issue

I have an issue with converting DateTime from Moscow timezone to New York timezone. Here is my test script: $year = 2015; $month = 3; $tzMoscow = new...
Jon Skeet
people
quotationmark

I think I've got it. The problem is that you're not specifying a time of day, so createFromFormat is using "the current system time": If format does not contain the character ! then portions of the generated time which are not... more 3/14/2015 2:25:31 PM

people

Java .jar executable not opening (on double click)

I wrote a little command-line game that has 5 classes: the main class "DiaDia.class", and the others "Partita.class", "Comando.class", "Stanza.class", "Attrezzo.class". Then i...
Jon Skeet
people
quotationmark

I wrote a little command-line game That's the problem then. javaw.exe is designed to run GUI applications - it doesn't allocate a console. If you change the file association for .jar to run java.exe instead, it will launch a console... more 3/14/2015 1:25:54 PM

people

Linq error: "string[] does not contain a definition for 'Except'."

Here's my code: public static string[] SplitKeepSeparators(this string source, char[] keptSeparators, char[] disposableSeparators = null) { if...
Jon Skeet
people
quotationmark

Your substrings variable is a string[], but disposableSeparators is a char[] - and Except works on two sequences of the same type. Either change disposableSeparators to a string[], or use something like: return... more 3/14/2015 12:26:13 PM

people

How do I build a method that returns an action with a constrained parameter?

I have a common encapsulation I've been using in my controllers to handle alert message passing, exceptions, and error logging. Here is a simple version of it: private void...
Jon Skeet
people
quotationmark

I suspect you just want: public Action<T> Builder<T>() where T : DbContext Then you could call it as: Action<SpecificDbContext> actionHelper = Builder<SpecificDbContext>(); You don't need the type argument, as... more 3/13/2015 10:28:09 PM

people

Why can't select come first in a LINQ query?

In a LINQ query, the order of operators is from-where-select: int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; var numQuery = from num in numbers where (num %...
Jon Skeet
people
quotationmark

What is the reason behind this restriction? I believe the primary reason was actually Intellisense. Until an IDE knows what sort of collection you're using, it can't suggest which properties you want to use from the elements of that... more 3/13/2015 8:28:04 PM

people

Unable to cast object of type 'system.windows.forms.textbox' to type 'System.IConvertible' error

I know my code is really bad but im still learning yet I dont understand this message can anyone explain where I have went wrong private void btnCalculate_Click(object sender,...
Jon Skeet
people
quotationmark

You're currently trying to convert the textboxes themselves to integers. That's not going to work. You need to convert the text within the textboxes: iDay1 = Convert.ToInt32(txtBox1.Text); (etc). You should absolutely definitely stop... more 3/13/2015 7:57:24 PM

people

Enumerable.Zip to enforce same lengths

I found myself frequently need to use Enumerable.Zip(), but having it to ensure the two IEnumerables to have the same length (or both to be infinite). E.g., if one enumerable...
Jon Skeet
people
quotationmark

I would probably just reimplement Zip the way you want to. It's really pretty simple - the following is trivially adapted from MoreLINQ. You'll want to give it a better name, mind you... public static IEnumerable<TResult>... more 3/13/2015 7:20:20 PM

people

TZ database and multiple US timezones

I am using pytz to associate time zones with my user profiles. Originally I thought it would just include time zones such as PST, CST, EST, but when I run...
Jon Skeet
people
quotationmark

For example, America/Kentucky/Louisville is the same as America/Kentucky/Monticello - why do they both exist? Because they're not the same. They may observe the same rules from now onwards, but they haven't always done so. Having... more 3/13/2015 7:04:16 PM

people

Home much memory does the JVM need to allocate a character array?

Consider to following 1 line program: public static void main(String[] args) throws Exception { // 134217728 * 2 bytes / 1024 / 1024 = 256M char[] array = new...
Jon Skeet
people
quotationmark

I believe you're observing the way that the Oracle JVM allocates memory. In particular, the whole array has to fit into one "generation". By default, the old generation is twice the size of the new generation - which means for every 3MB... more 3/13/2015 6:59:08 PM

people