Browsing 7239 questions and answers with Jon Skeet

Can I use value of a local variable defined in a method, in other method in java? (Please read before down voting.)

The method is not returning the value of the local variable. Can I use the value of local variable index from the following method public boolean contains(Object input) { ...
Jon Skeet
people
quotationmark

No. The whole point of it being local to a method is that it only exists within that method. The options are: Use an instance field, i.e. make it part of the state of the object. That's unlikely to be appropriate. Use a static field,... more 3/13/2015 8:07:58 AM

people

List to Dictionary<Key, List<Value>> C#

I have a List and MyClass is: public class MyClass { public bool Selected { get; set; } public Guid NoticeID { get; set; } public Guid TypeID { get; set; } } My...
Jon Skeet
people
quotationmark

Well, when you group you can specify the value you want for each element of the group: var dictionary = list.GroupBy(p => p.TypeID, p => p.NoticeID) .ToDictionary(p => p.Key, p => p.ToList()); However, I... more 3/13/2015 7:22:13 AM

people

How to get byte array from list?

I am adding some data to super list and trying to convert that list to byte[], but getting class cast exception. Below is my code. public byte[] getBytes () { Byte[]...
Jon Skeet
people
quotationmark

Your toArray call needs to tell the list what kind of array to create: Byte[] arrayByte = super.toArray(new Byte[size()]); That can't otherwise be inferred at execution time, due to type erasure - the list doesn't "know" that it's a... more 3/13/2015 6:45:08 AM

people

Changing timezone to IST

I am programmatically trying to set the timezone to Indian Standard Time (IST) in Android, but nothing seems to work! Here's the code snippet: SimpleDateFormat s = new...
Jon Skeet
people
quotationmark

Rather than changing the default time zone (which you're doing after creating the SimpleDateFormat) you should just set the time zone of the SimpleDateFormat: SimpleDateFormat s = new... more 3/12/2015 6:58:24 PM

people

LINQ and C# Dealing with a potentially null parameter

I am relatively new to LINQ but looking for some "best practice" advice on how to deal with the following. I know there are many ways to deal with this, but looking to see how...
Jon Skeet
people
quotationmark

It sounds like you just want: where c.CONCOM == concom && (engineer == null || c.LOPER == engineer) Alternatively, you could build up the query step by step: var query = db.RPTINQUIRies.Where(c => c.CONCOM == concom); if... more 3/12/2015 2:14:35 PM

people

Is TimeZone.getDSTSavings() in java returns always positive value?

Is TimeZone.getDSTSavings() in java returns always positive value or Negative values also? I have tried this way long millisecondsForGivenDateTime = 0l; if...
Jon Skeet
people
quotationmark

In theory it could return a negative value - if you were using a TimeZone subclass where daylight saving time caused clocks to go back rather than forward. I very much doubt you'll see that in the wild, although I have seen something... more 3/12/2015 1:01:12 PM

people

How can I diagnose missing dependencies (or other loader failures) in dnx?

I'm trying to run a modified version of the HelloWeb sample for ASP.NET vNext on DNX using Kestrel. I understand that this is very much on the bleeding edge, but I would hope that...
Jon Skeet
people
quotationmark

I still don't know entirely what was wrong, but I now have a series of steps to at least make it easier to try things: When in doubt, reinstall dnx Blowing away the package cache can be helpful Check ~/.config/NuGet.config to ensure... more 3/12/2015 12:41:13 PM

people

Why in order to compare hijri with iso dates you need to wrap a DateTime in LocalDateTime? (Joda)

I am trying to convert an ISO (Gregorian) date into a hijri (Islamic) date and the compare the first to a hijri date. What I do and it does not work is: Chronology iso =...
Jon Skeet
people
quotationmark

This is not what you want: DateTime hijriDt = new DateTime(formatter.parseDateTime("1442-05-21 10-10"), iso); That's not using the Hijri calendar anywhere: Your formatter is using ISO (by default) You're parsing a date in year 1442... more 3/12/2015 11:59:54 AM

people

java.lang.ClassCastException on creating an Array of classes in java

I want to create an array of classes and I have these: 1)works fine Class<MyClass>[] array = (Class<MyClass>[]) new...
Jon Skeet
people
quotationmark

Both snippets 2 and 3 are creating a MyClass[], not a Class<MyClass>[]. The element type is determined by the first argument to Array.newInstance. If you want an array where each element is a Class reference, you need to pass in... more 3/12/2015 10:27:02 AM

people

XML Select xmlNode depending on innertext

I have a 'xmlDocument'-Object, which contains this structure: <Projects> <Project> <Name>Value1</Name> </Project> <Project> ...
Jon Skeet
people
quotationmark

I would suggest using LINQ to XML instead of XPath: XDocument doc = ...; // However you load the XML XElement element = doc.Root .Elements("Project") .Elements("Name") ... more 3/12/2015 10:06:42 AM

people