Browsing 7239 questions and answers with Jon Skeet

How to open and run devenv \ build command in Developer Command Prompt for VS2013?

I would like to build a VS 2013 project from the command line. After manually open the "Developer Command Prompt for VS2013", changing the directory to the project directory and...
Jon Skeet
people
quotationmark

It's probably easier to create a batch file to call devenv (if you really need to) but otherwise, I suspect it's just a matter of how you're quoting - and that you've got a > in your path to devenv.exe. Try: string devEnv =... more 1/13/2015 11:46:00 AM

people

how to parse date using SimpleDateFormat in java of type 2015 01 13T10:24:55Z

i have the following date string coming from grails services in android app. 2015-01-13T10:24:55Z Now i want to parse this string using...
Jon Skeet
people
quotationmark

Currently you're using the "general time zone" specifier. In order to have Z interpreted as "this value is in UTC", you should use X: new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.US) X is an ISO-8601 time zone specifier, which... more 1/13/2015 11:12:12 AM

people

Weird generics error

I'm trying to implement following structure using generics. Getting a weird compiler error, can't figure out why. class Translator<T:Hashable> {...} class...
Jon Skeet
people
quotationmark

I'm not a Swift developer, but having seen similar problems in Java, I suspect the problem is that at the moment you're declaring a type parameter called String because you're declaring class FooTranslator<String> - so the type... more 1/13/2015 11:00:13 AM

people

Dividing all values of a dictionary by a value

I have the following code in C# where vector is a [string,double] type of Dictionary.I want to divide all values in this dictionary by a value, "magnitude". Now, my naive first...
Jon Skeet
people
quotationmark

The simplest way to do this is just to copy the list of keys before iterating: foreach (var key in vector.Keys.ToList()) { vector[key] = vector[key] / magnitude; } Or: foreach (var entry in vector.ToList()) { vector[entry.Key]... more 1/13/2015 9:50:36 AM

people

Google drive, upload MemoryStream

This code is working well: img.Save("111.png", System.Drawing.Imaging.ImageFormat.Png); using (MemoryStream fileStream = new...
Jon Skeet
people
quotationmark

I wouldn't like to say why you're getting that particular error, but after you've called Save, the stream's "cursor" is at the end of the data, so there's no data for Insert to read. You should rewind the... more 1/13/2015 7:17:09 AM

people

How to find the longest sequence of consecutive natural successors?

Two consecutive integers are natural successors if the second is the successor of the first in the sequence of natural numbers (1 and 2 are natural successors). Write a program...
Jon Skeet
people
quotationmark

When you see the first number out of sequence, you should reset counter to 1, not 0 - as it's the start of a sequence with length at least 1. You then need to also change the code which changes max: if (counter > max) { counter =... more 1/13/2015 7:09:02 AM

people

Deserializing with Json.Net, deserialize sub object into string/similar holding the json?

I am trying to create a configuration file using Json that will hold configuration for various types of objects. Consider this file: { "cameras": [ { ...
Jon Skeet
people
quotationmark

It looks like if you use a property of type JObject, that parses but preserves the JSON: using System; using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public class Foo { public string Name { get; set; } ... more 1/12/2015 10:17:14 PM

people

Reading unsigned bytes with RandomAccessFile

I have this method using a RandomAccessFile descriptor: public byte[] readByte(int number) { try { byte[] buffer = new byte[number]; ...
Jon Skeet
people
quotationmark

You're casting the result of readUnsignedByte to byte - so if the result is 255 as an int (for example) it is -1 after casting to byte. byte is always signed in Java - it always has a range of [-128, 127]. There's nothing you can do about... more 1/12/2015 9:51:06 PM

people

ShakeGestures Instance/Event appears to be "global" throught the WP8 App

So, I have a WP8 app with multiple pages. I'm using ShakeGestures.dll in my app to detect the shakes. On different pages (except the MainPage.xaml) I have separate-indepenent...
Jon Skeet
people
quotationmark

Well yes, as indicated by the XML documentation, ShakeGesturesHelper is a singleton, and you access the single instance with ShakeGesturesHelper.Instance. So you're registering a new event handler each time you... more 1/12/2015 9:41:01 PM

people

Raising warnings based on class attributes

Here is some code: class Program { static void Main(string[] args) { MyClass class1 = new MyClass(); MyOtherClass class2 = new MyOtherClass(); ...
Jon Skeet
people
quotationmark

If you're happy to either use the VS 2015 preview or wait until VS 2015 is out, you can use Roslyn for this. You'd write a DiagnosticAnalyzer class, probably registering a syntax node analyzer to specifically look for invocations of... more 1/12/2015 3:06:12 PM

people