Browsing 7239 questions and answers with Jon Skeet

Java 8 DateTimeFormatter dropping millis when they're zero?

This seems weird. Java 8 is formatting the output differently depending on whether the millis is zero. How do you force Java 8 (1.8.0_20) to always spit out the millis regardless...
Jon Skeet
people
quotationmark

You don't use ISO_OFFSET_DATE_TIME, basically :) If you follow the documentation for that, you end up in the docs of ISO_LOCAL_TIME which has: This returns an immutable formatter capable of formatting and parsing the ISO-8601 extended... more 2/3/2016 6:18:13 PM

people

I'm not able to run a class file on the command line even though there are no problems with Java installation and path variables settings

I've been using Eclipse to practice programming Java for a while. Haven't got any problems so far, but today I just wanted to compile and run my code on the command line (I'm...
Jon Skeet
people
quotationmark

The problem is your CLASSPATH environment variable. It exists, but doesn't include the current directory. Unless you really need the CLASSPATH environment variable for some reason, I would remove it - then it will default to just the... more 2/3/2016 4:11:45 PM

people

Exception InInitializer Error for public static integer

I have a code where I need to call number of Jobs as public static integers from Size.txt file as follows: public class GetJobs { public static int Jobs = valueN(), inp = 4; ...
Jon Skeet
people
quotationmark

This is the problem: public static int Jobs = valueN(), inp = 4; ... public static int valueN(){ ... int[] MN = new int [inp]; ... n=MN[0]; } When you run valueN(), inp is still 0. The initialization which will set inp... more 2/3/2016 1:52:19 PM

people

How to get array of int as json result in mvc 4?

This is my json code. public JsonResult GetCheckedPerm(int usr_groupId) { List<int> selectedradio = GrpPermBAL.GetData(usr_groupId); ...
Jon Skeet
people
quotationmark

You just need to call the Json method, inherited from the controller base class: return Json(selectedradio, JsonRequestBehavior.AllowGet); more 2/3/2016 11:47:16 AM

people

.NET Core alternative to ThreadPool.QueueUserWorkItem

I'm working on implementing the ForgotPassword functionality ie in the AccountController using ASP.NET Identity as in the standard VS 2015 project template. The problem I'm...
Jon Skeet
people
quotationmark

Just don't await the task. That's then mostly-equivalent to running all of that code on the thread-pool to start with, assuming it doesn't internally await anything without calling ConfigureAwait(false). (You'll want to check that, if it's... more 2/3/2016 11:39:43 AM

people

Linq query to get result of query as array of int

This is my table. grp_perm_id grp_id Perm_id 23 2 2 27 2 1 28 3 1 29 2 3 I want to retrieve...
Jon Skeet
people
quotationmark

You're currently selecting the whole row, rather than just the perm_id. You're also calling ToArray twice, and trying to return an array despite your method's return type being List<int>. I'd just use: public List<int>... more 2/3/2016 11:11:34 AM

people

dictionary.TryGetValue vs FirstOrDefault

According to MSDN documentation, a Tuple objects Equals method will use the values of the two Tuple objects. Why does the following not produce the same result: [Test] public...
Jon Skeet
people
quotationmark

You're using ==, which isn't overloaded for Tuple<,>, so it's using a reference identity check... and as you've constructed a new tuple, that will never be true. This would be correct, but undesirable: // Don't do... more 2/3/2016 9:02:13 AM

people

Why does asp.net fileupload control corrupt files?

I am using FileUpload control to upload multiple files and it does successfully but problem is that when I download files after uploading then it becomes corrupt i.e. .pdf, .docx...
Jon Skeet
people
quotationmark

It looks like this is the problem: FileUpload1.PostedFile.SaveAs(Server.MapPath("~/SiteImages/") + fileName); That's saving the first file multiple times - you're trying to save the file you're currently referring to as uploadedfiles... more 2/3/2016 8:01:05 AM

people

Is it a bug that Java 8's HashMap misbehaves if the keys implement Comparable in a way that isn't consistent with equals?

I know that since Java 8, if a HashMap has enough hash collisions, and the keys implement Comparable, it will use a balanced tree instead of a linked list for the bin. But from...
Jon Skeet
people
quotationmark

It's not a bug anywhere IMO, in that the code is behaving as the implementor expected - but this is a known result of an unusual Comparable implementation. From the Comparable documentation: It is strongly recommended (though not... more 2/2/2016 10:16:39 PM

people

c# : comparing two lists and recording change in value

most answers that I have seen here are mostly covering the issue of boolean true/false upon list comparison. What I am interested in is comparing two lists and seeing the change...
Jon Skeet
people
quotationmark

It sounds like you just want something like: var differences = aList.Zip(bList, (a, b) => new { a.Name, Difference = a.Grade - b.Grade }); foreach (var result in differences) { if (result.Difference != 0) { ... more 2/2/2016 10:01:21 PM

people