Browsing 7239 questions and answers with Jon Skeet

List not getting initialized c#

For the following code below, the foreach loop in the main() method is not displaying any values. i.e. my list is not getting initialized for display. Please help me. Thanks in...
Jon Skeet
people
quotationmark

You've got several variables all called allProducts: The static variable The parameter in InitialiseMyProducts The local variable in Main You're initializing the local variable in Main twice, then passing it to InitialiseMyProducts (or... more 5/4/2014 6:41:54 AM

people

Java Menu going into an infinite loop

i'm getting an infinite loop with the program i'm doing and i'm not sure how to get passed it. been working at this a few hours and i cant figure it out. (sorry if this seems...
Jon Skeet
people
quotationmark

The problem is that arguments to methods are passed by value in Java. So the part at the end of displayMenu where you set a new value for the selection parameter doesn't change the value of the selection local variable in main at all. So... more 5/3/2014 7:45:27 PM

people

Why does Java compiler refuse to recognize System.exit() as a procedure termination?

Java's compiler, at least the one from Oracle that I use, refuses to recognize System.exit() as a procedure termination. For example, the following code gives a compilation...
Jon Skeet
people
quotationmark

Java's compiler, at least the one from Oracle that I use, refuses to recognize System.exit() as a procedure termination. Yes, it would. As far as the compiler is concerned, it's just a void method. There's no way of indicating "this... more 5/3/2014 3:45:34 PM

people

Correct insert DateTime from c# to mongodb

I try to insert local time in MongoDB var time = DateTime.Now; // 03.05.2014 18:30:30 var query = new QueryDocument { { "time", nowTime} }; collection3.Insert(query); But...
Jon Skeet
people
quotationmark

I think you're getting confused by time zones. The Z at the end of the string indicates that it's in UTC. When you posted this question, it was just after 15:30 UTC. I strongly suspect that the correct instant in time is being recorded -... more 5/3/2014 3:39:22 PM

people

How to TryParse for Enum value in NET 3.5?

I have to work with .NET 3.5 but want to use TryParse method which I know belongs to .NET 4.0. Then I searched the web for the subject and I think I found the best solution in...
Jon Skeet
people
quotationmark

As the error message is saying, you need to pass the type of the enum as the first argument. You also need to change the type of myValue to match the out parameter of EnumTryParse, so: object myValue; if... more 5/3/2014 10:09:09 AM

people

How to change this method to a Set instead of ArrayList

How could I change this method to remove all odd length strings in a TreeSet instead of an array? public void removeOddLength(ArrayList<String> list) { for (int...
Jon Skeet
people
quotationmark

Well your method is already broken, in that it won't consider all the strings - if you have {"foo", "bar", "ab", "cd" } then you'll still be left with "bar" afterwards, because of the way you're iterating. It's generally a pain to mutate... more 5/3/2014 6:05:01 AM

people

What is the lifespan of a static variable

In the following code, does Nail's reference to ypaw end as soon as I exit the method someMethod or is there potential for leakage? Also, once I exit class Dog are all references...
Jon Skeet
people
quotationmark

No, a static variable lives for as long as the classloader which loaded the class does. So that's "forever" in many applications. It's not clear what you're trying to achieve, but this code is almost certainly a bad idea. (In general,... more 5/2/2014 8:07:17 PM

people

How to convert UTC Date Time to Local Date time without TimeZoneInfo class?

i want to convert UTC date time to local date time by myself and do not want to use .net TimeZoneInfo or other classs about this. i know Tehran is a GMT offset of +03:30 i use...
Jon Skeet
people
quotationmark

i know Tehran is a GMT offset of +03:30 Well, that's its offset from UTC in standard time, but it's currently observing daylight saving time (details). So the current UTC offset is actually +04:30, hence the difference of an hour. I... more 5/2/2014 5:21:45 PM

people

How to check string is English or German or any other language other than English using java

I have to prepare a property file where key is English and value can be other than English, like German, Chinese, Korean, French. I read key and value from xml file. I used one...
Jon Skeet
people
quotationmark

I would strongly advise you to have separate property files, one for each language. Heck, that's the scenario that PropertyResourceBundle is made for. Fundamentally you can't tell what language a word is - there are many words which are... more 5/2/2014 5:15:04 PM

people

File lastModified() returns Wed Dec 31 19:00:00 EST 1969

I was doing some testing with files like this: public Date findFileDate(){ File file = new File(filePath); Date date = new Date(file.lastModified()); return...
Jon Skeet
people
quotationmark

No, file.lastModified() is returning 0. That's the Unix epoch In your particular time zone (Eastern US by the looks of it), local time at the Unix epoch was 5 hours behind UTC, so it was 7pm on December 31st 1969. To confirm this, just... more 5/2/2014 5:00:06 PM

people