Browsing 7239 questions and answers with Jon Skeet

Noda Time WeekOfWeekYear starting Sunday and not Monday

While working with Noda Time I am trying to base some data on the WeekOfWeekYear, What I have noticed is that the WeekOfWeekYear property changes on a Monday yet I need it to...
Jon Skeet
people
quotationmark

No, ISO-8601 explicitly specifies that calendar weeks start on Monday - and "week of week year" is basically following ISO-8601. If you want a different week and day numbering scheme, you'll currently have to create your own. (It may well... more 6/24/2014 10:43:21 AM

people

Why use static enum?

Sometimes I saw use static enum in android. but I can't find that information(I know enum in C) example, public static enum brush{ static{ array[0] =...
Jon Skeet
people
quotationmark

The problem is that this is an enum without a list of members. You'd normally have: public enum Foo { VALUE1, VALUE2; } You can have an enum with no members, but you still need the semi-colon: public enum Foo { ; } That's now... more 6/24/2014 9:51:17 AM

people

Zipping a list in thread safe manner

At the moment, I am using the following pseudo-code: List<MyMail> m = new List<MyMail>(); foreach(var user in users) { var mails = mailLibrary.getAllMails(user);...
Jon Skeet
people
quotationmark

Have you considered using Parallel LINQ instead? return users.AsParallel().AsOrdered() .SelectMany(user => mailLibrary.getAllMails(user)) .ToArray(); I believe that will do the right thing, in terms of... more 6/24/2014 9:39:09 AM

people

Java and naming of method to get enum from int

I have an enum, where each enum maps to an integer, which doesn't match with enum's ordinal(). And now I need a method to convert integer to enum. I think have two options: A...
Jon Skeet
people
quotationmark

Presumably the number means something - so I'd create a method which uses that information. For example: public enum HttpStatus { OK(200), ... NOT_FOUND(404); private int statusCode; private HttpStatus(int... more 6/24/2014 8:32:46 AM

people

Collections.sort() isn't sorting in the right order

I have this code in Java: List<String> unSorted = new ArrayList<String>(); List<String> beforeHash = new ArrayList<String>(); String[] unSortedAux,...
Jon Skeet
people
quotationmark

The problem is that "Carlos Magno" starts with a Unicode byte-order mark. If you copy and paste your sample text ([Analise ... Carlos Magno]) into the Unicode Explorer you'll see that just before the "C" of Carlos Magno, you've got... more 6/23/2014 6:59:47 PM

people

C# not inferring overloaded method via return type

I'm writing a C# programlet to crawl a directory and give me a listing of files whose date in the last CSV line is less than the current date. Since this is a programlet, I'm not...
Jon Skeet
people
quotationmark

So I suppose C# does not overload return types? No, indeed it doesn't. The return type isn't part of the signature. From section 3.6 of the C# 5 specification (emphasis mine): The signature of a method consists of the name of the... more 6/23/2014 6:46:15 PM

people

PBKDF2WithHmacSHA1 confusing

Can anybody tell me what is the use of 128*8 in the code below? I have written the code for password encryption and I still don't know what this 128*8 is doing. This is what I...
Jon Skeet
people
quotationmark

The 128*8 is the requested key length, as per the documentation. keyLength - the to-be-derived key length. It's not clear that it's in bits, but it is. So you're asking for a key which is 1024 bits long (because 128 * 8 =... more 6/23/2014 2:52:51 PM

people

Function initialisation

Is it necessary to always initialise the result variable in the function For example Public class Calculator result=addition(a,b); Public static int addition(int a, int...
Jon Skeet
people
quotationmark

You don't need to have a result variable at all. You need to make sure that every possible way that execution can reach the end of your function (without just throwing an exception) means you get to a return statement, and every return... more 6/23/2014 2:27:54 PM

people

HashCode for conditional equals

I would like to generate a hash-code for the following equals-method. public MyClass class { private int a; private final String b; public boolean equals(Object o) { ...
Jon Skeet
people
quotationmark

Forget the hash - your equality comparison is fundamentally broken to start with. Consider three values: foo: a=10, b=0 bar: a=10, b=5 baz: a=20, b=5 Now: foo.equals(bar) => true because of a bar.equals(baz) => true because of... more 6/23/2014 2:07:34 PM

people

Why do I receive an incorrect syntax error when try to parameterize a table name?

I have the following code: string strTruncateTable = "TRUNCATE TABLE @TableNameTruncate"; SqlCommand truncateTable = new SqlCommand(strTruncateTable, myConnection); ...
Jon Skeet
people
quotationmark

How can I fix the issue? By specifying the table name as part of the SQL. Table and column names can't be parameterized in most database SQL dialects, including SQL Server. You should either perform very stringent validation on the... more 6/23/2014 1:58:22 PM

people