Browsing 7239 questions and answers with Jon Skeet

Converting PST time to Local device time in android

I am trying to convert PST time to Device local time using below function. It works fine but in London timezone its not working properly. If its 04:58 AM PST then it should show...
Jon Skeet
people
quotationmark

I agree with Moritz that using Joda Time would make the code simpler, but you should be able to do all of this much more simply than your current approach: public String getTimeRelativeToDevice(String pstTime) { SimpleDateFormat sdf =... more 6/23/2015 4:01:26 PM

people

Can't access any of Linq methods

I'm writing a simple ApiController for getting product stocks, but I'm having a strange issue. I get the data from a method that returns a System.Linq.IQueryable (In a library),...
Jon Skeet
people
quotationmark

The non-generic IQueryable interface doesn't have extension methods of Count and ToList(). Only the generic IQueryable<T> does. If you can modify the library to return a suitable IQueryable<T>, I suggest you do so. If you... more 6/23/2015 12:04:36 PM

people

How to parse JSON array of string arrays

Lets say I get the following json data from a web service which I can't change. [ [ "Header1", "Header2", "Header3", "Header4" ], [ ...
Jon Skeet
people
quotationmark

Simple - you can use JsonConvert.DeserializeObject to deserialize it to a string[][]: using System; using System.IO; using Newtonsoft.Json; class Test { static void Main() { var json = File.ReadAllText("test.json"); ... more 6/23/2015 9:05:30 AM

people

unable to add System.speech reference in visual studio 2013

trying to add System.speech reference in studio 2013.. but not able to find speech extension in dialog box. explain how to add correctly.. running windows 8.1
Jon Skeet
people
quotationmark

You're targeting Windows Phone 8.1. As far as I can tell, System.Speech is only supported by the desktop framework (either the full framework from v3.0, or the client profile from v4.0). more 6/23/2015 8:55:43 AM

people

Passing a generic as parameter to DateTime's constructor

As you know PCL doesn't support PersianCalendar or GregorianCalendar class, So I'm using generic to achieve that, In this case consumer can pass the Calendar to the class: public...
Jon Skeet
people
quotationmark

As you've noted, DateTime doesn't have the constructor you want in the PCL. However, you can use Calendar.ToDateTime: return CurrentCalendar.ToDateTime(year, month, day, hour, minute, 0, 0); As an aside, you could change your generic... more 6/23/2015 7:41:59 AM

people

Wrong output when attempting to read a text file

I would like to read and print the text file to console so i did this with below code File file = new File("G:\\text.txt"); FileReader fileReader = new FileReader(file); int...
Jon Skeet
people
quotationmark

Your file starts with a byte-order mark (U+FEFF). It should only occur in the first character of the file - it's not terribly widely used, but various Windows tools do include it, including Notepad. You can just strip it from the start of... more 6/23/2015 6:08:57 AM

people

How to write text to a specific line in Visual Studio C#

I'm wondering if there is a way to write data from the program to a specific line on an external text document. For example, so far within my program I have a string array which...
Jon Skeet
people
quotationmark

Well, the simplest approach would be: string[] lines = File.ReadAllLines(path); lines[index] = newText; File.WriteAllLines(path, lines); However, that assumes that there's already an appropriate number of lines in the file - is that... more 6/22/2015 6:26:07 PM

people

XElement.Value is stripping XML tags from content

I have the following XML: <Message> <Identification>c387e36a-0d79-405a-745c-7fc3e1aa8160</Identification> <SerializedContent> ...
Jon Skeet
people
quotationmark

You're using the Value property, which is documented to return the concatenated text descendant nodes within the element. So it sounds like you want a concatenation of the string representations of all the child nodes. So you could... more 6/22/2015 4:57:32 PM

people

Empty constructor in inheriting class C#

I have written a simple generic class in C#. class Foo<T> { public object O{get;set;} public Foo(object o) { O=o; } } and another class inheriting from...
Jon Skeet
people
quotationmark

No, you can't. There's no inheritance of constructors. The constructor in Bar does do something: it provides an argument to the base constructor, using its own parameter for that argument. There's no way of doing that automatically. The... more 6/22/2015 4:12:17 PM

people

Overload precedence between Expression<Action> and Expression<Action<T>>

The short version: What is the best way of overloading two methods, when one accepts an Expression<Action>, and another accepts an Expression<Action<T>>? The...
Jon Skeet
people
quotationmark

Currently, neither of your methods is applicable - because type inference can't infer T for your second method, and the first method is invalid because your anonymous function has a parameter (unlike Action). The compiler is reporting an... more 6/22/2015 2:15:51 PM

people