Browsing 7239 questions and answers with Jon Skeet

How does parsing a c# date to be a javascript date even work with the ')'?

I know that to convert a C# date, like /Date(1430341152570)/ to a JavaScript date, it's the following: var part = "/Date(1430341152570)/".substr(6); // =>...
Jon Skeet
people
quotationmark

From the Mozilla documentation: If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates... more 4/30/2015 12:21:48 PM

people

Why am i being told my model property (id) doesn't exist, when it does?

I have a model property RegimeItemID which I am using in my controller. However, when I am trying to call it, it is giving an error that it doesnt exist. What have I done...
Jon Skeet
people
quotationmark

RegimeItems is a collection of RegimeItem elements - it's not a single element, so it doesn't have a single ID. It sounds like you may want something like: return db.Users .Where(r => r.RegimeItems.Any(ri =>... more 4/30/2015 11:00:17 AM

people

Writing to a file asynchronously, but in order

I've got some code which saves data from an object to XML. This locked the UI for a few seconds so I made it so it wouldn't. foreach (Path path in m_canvasCompact.Children) { ...
Jon Skeet
people
quotationmark

It sounds like you want a producer/consumer queue. You can rig that up fairly easily using BlockingCollection<T>. Create the blocking collection Start a task which will read from the collection until it's "finished" (simplest with... more 4/30/2015 8:40:37 AM

people

OOP inheritance and default constructor

Suppose there is a base class A and a class B derived from A. Then, we know that the constructor of class A is never inherited by class B. However, when a new object of B is...
Jon Skeet
people
quotationmark

Now, on creating a new instance of class B, which constructor of class A is automatically called before invoking the class B constructor? The code will fail to compile, basically. Each constructor has to chain to another constructor,... more 4/30/2015 5:45:06 AM

people

Return expression instead result

If I have function like this double GetExpression(int x, int y, int z) { return x * y + z; } is it possible to modify it somehow, to not return result immediately only some...
Jon Skeet
people
quotationmark

Well, you could use delegates, and return a Func<double>: Func<double> GetExpression(int x, int y, int z) { return () => x * y + z; } var expression = GetExpression(1,2,3); double result = expression(); // Or... more 4/29/2015 8:52:53 PM

people

Get all values of Enum with specific integer value c#

How to get all values of enum with integer value in this example enum colour { red = 1, green = 1, blue = 1, yellow = 2, cyan = 2, purple = 2 } I mean, by inputting 1, I want...
Jon Skeet
people
quotationmark

Well, firstly I would strongly recommend that you don't do this. Having multiple names for the same value is a really bad idea, IMO. However, you can do it with reflection: using System; using System.Collections.Generic; using... more 4/29/2015 5:51:04 AM

people

Passing inline constructed class as a Class argument to a method

I need to call following method. void foo(Class<? extends Bar> cls); For cls argument, I need to pass a class that only overrides a single method of Bar. I want to know...
Jon Skeet
people
quotationmark

Three options: You could create a nested class within the same class you want to use this code; no need for a new file public static void doSomething() { foo(Baz.class); } private static class Baz extends Bar { // Override a... more 4/29/2015 5:42:52 AM

people

Is it necessary to create a Java class everytime?

I am starting to learn the Java programming language and I am a little confused. I would like to create a simple program like adding two numbers or calculate the sum of n...
Jon Skeet
people
quotationmark

Can I just create the program directly the way I do it in other languages? No. I mean is the concept of class necessary in Java? Yes. Every method, field etc is always in a class (or interface). Yes, that's an overhead for tiny... more 4/28/2015 6:50:26 PM

people

LocalTime from Date

I'm trying to convert a Date instance to a LocalTime instance. // Create the Date Date date = format.parse("2011-02-18 05:00:00.0"); // Convert to Calendar Calendar cal =...
Jon Skeet
people
quotationmark

Your input is effectively a LocalDateTime. It would be much simpler to simply parse that to a LocalDateTime and then get the LocalTime from that. No time zones to worry about, no somewhat-legacy classes (avoid Date and Calendar where... more 4/28/2015 6:49:24 PM

people

Local variables and thread safety

In Java if you have the following method: public int foo(int n) { int i=n; i = i+1; i = i-1; return i; } So in a sequential program the return value will always be...
Jon Skeet
people
quotationmark

I would say yes that it is guaranteed, because i is a local variable, and each thread has its own stack so i will be a different memory location for each thread. Exactly. Each call to foo will be independent, because foo isn't using... more 4/28/2015 4:20:31 PM

people