Browsing 7239 questions and answers with Jon Skeet

DateTime Format provider for filepath

I have a file-path that's been created from DateTime stamp: "C:\\Logs\\Tests\\2015\\Mar\\24\\13_32_09\" Now I am trying to convert my file-path back to DateTime object. With...
Jon Skeet
people
quotationmark

No, you don't need to create an IFormatProvider at all. The invariant culture is fine for this (assuming the month name is always in English). You can just use DateTime.ParseExact, passing in the appropriate custom format string (quoting... more 3/24/2015 7:21:43 PM

people

Deep equal issue about boolean method with a Object argument

I am writing a class called Coord. I have created a constructor: public final int r,c; public Coord (int r, int c){ this.r = r; this.c = c; } I also did another two methods ...
Jon Skeet
people
quotationmark

Is there a deep equal issue here? Well yes, your equals method just checks whether the value passed to it is the same reference. Your comment says what you want to do: //Given another object, is it also a Coord with the same row and... more 3/24/2015 6:36:45 PM

people

Wait for some second then execute button action WPF

I try to make button click by wait x second over this button then perform his action, I use System.Windows.Forms.Timer to make that in Win-form but how can make the same thing in...
Jon Skeet
people
quotationmark

Well you could use a DispatcherTimer instead, but it's probably simplest to use an async method and Task.Delay: public async void Foo(object sender, RoutedEventArgs e) { await Task.Delay(5000); DoSomething(); } more 3/24/2015 2:03:16 PM

people

ArrayList<Integer> takes String

public class Main { public static void main(String[] args) { ArrayList<Integer> ar = new ArrayList<Integer>(); List l = new ArrayList(); ...
Jon Skeet
people
quotationmark

But how can we add strings to arraylist whose type has already been specified as Integer? Because of the way Java generics was designed for backwards compatibility, with type erasure and raw types, basically. At execution time,... more 3/24/2015 1:05:59 PM

people

Exception handling technique between class library and other projects

I'm little bit confused about handling exceptions within a hierarchy of methods. Let's say, I've a class Logger in a class library project. Please have a look on the following...
Jon Skeet
people
quotationmark

Do I actually need try.. catch in every method? No. In fact, it's harming your diagnostics by cutting off the stack trace - you won't be able to see the original full stack trace. You could fix that by just using: throw; instead... more 3/24/2015 10:27:32 AM

people

Read Json Data.But able to access the second Object

How To Read this Data "Data": [ { "Candidate Details": { "Salutation": "au.linkedin.com/in/324234", "First Name": "test (Demo)", ...
Jon Skeet
people
quotationmark

Your array only has one entry - which in turn has properties of "Candidate Details", "[Current Residential Address]" etc. (It's not clear whether this really need to be an array at all.) If you want to iterate over all the properties, you... more 3/24/2015 8:34:16 AM

people

Solving the no console error

I am learning regex,when I compile this code which is from Java Official documentation, I am getting No Console error in this code,The source is, I am compiling this code in...
Jon Skeet
people
quotationmark

but I do not know why the error is caused Presumably because you're not running it in a console. When you run a Java app in Eclipse, System.console() returns null, because it's not a "normal" console. (Personally I think it would be... more 3/24/2015 7:11:06 AM

people

C# Template method override in concrete class from abstract base class

I have the following code which has a Base class containing an abstract template method, which in the derived classes is overridden using concrete types. class MyObj { private...
Jon Skeet
people
quotationmark

You appear to be trying to provide an implementation for one specific type argument. You can't do that, and it doesn't make sense - it's not clear what would happen if the caller passed in a different type argument, e.g. Base b = new... more 3/24/2015 6:50:25 AM

people

final variable not const enough for switch case

I have the following code: public class Main { static final String fu = Week.class.getName(); public static void main(String[] arg0){ String h = "dummy"; ...
Jon Skeet
people
quotationmark

Why is this not enough Because it's not a compile-time constant by the rules of JLS 15.28. Why is this not enough, what can I do (other than if-else)? Nothing, basically - unless you use a string literal, which would obviously... more 3/23/2015 6:46:59 PM

people

c# Lock Doesn`t work / Critical Section

I`m trying to advance a static (int) counter using two different threads in a FOR loop, so if the loop is runs 10 times I (should) get counter=20. for some reason i keep getting...
Jon Skeet
people
quotationmark

You've got three problems: You're actually running the loop 11 times: for (int i = 0; i <= ForLength; i++) // i=0 to i=10 *inclusive* You're not joining on your threads (or sleeping), so some of them may not have finished by the... more 3/23/2015 6:42:56 PM

people