Browsing 7239 questions and answers with Jon Skeet

java reading 2 byte integer in 2's complement from binary file into integer

I am trying to parse a binary file containing values. In the specs it says that each value is represented as a 2-byte integer in 2's complement format. I am reading the file into...
Jon Skeet
people
quotationmark

Yes - you're reading them in little-endian format (the first value is the least important) but you're writing them in big-endian format (the first value is the most important), assuming you're writing a then b. Just reverse the order when... more 2/14/2017 10:13:16 AM

people

Select method is not called using LinQ query syntax

I want to enable LinQ query syntax over my classes. I think query syntax is translated to method syntax, for example: var query = from p in new Class1<Product>() ...
Jon Skeet
people
quotationmark

Someone knows why? Yes, because that's what the language specification says to do. The query expression translation is all in section 7.16.2 of the C# 5 specification. Section 7.16.2.5 explains why your initial example is incorrect... more 2/13/2017 12:48:00 PM

people

C# func<> applied to the object on left

I'm trying to figure out if there's a way to use func (or a similar method) applied to the left object. Ex.: member1.MyFunction() Here's a simplified context of usage. We got...
Jon Skeet
people
quotationmark

Well not with quite that syntax, but you can just use: theSum += aFunction(aList[i]); I suppose you could write an extension method for this, but the above is more idiomatic. In fact, using LINQ to start with would be more idiomatic -... more 2/12/2017 7:34:36 PM

people

How to read byte array as a property from a Properties file

Suppose I have a properties file named features.properties with some of its properties encrypted in byte array format. e.g. color = [64, 14, 76, 92, 5, 114, 54, 31] I want...
Jon Skeet
people
quotationmark

with some of its properties encrypted in byte array format I suspect you don't actually mean "encrypted" here. You're just representing the bytes as text - I don't see any encryption. If they really are encrypted as well, that's a... more 2/11/2017 8:46:04 AM

people

Java replaceAll fails with dollar sign in source string

Say I have the following code String test = "$abc<>"; test = test.replaceAll("[^A-Za-z0-9./,#-' ]", ""); test is now "$abc". Why does it keep the dollar sign?
Jon Skeet
people
quotationmark

Your list of characters to preserve includes #-', which is a range from Unicode U+0023 (the # symbol) to U+0027 (the ' symbol), including $ (U+0024). If you meant #-' to be interpreted as a list of three characters, just escape it: test... more 2/10/2017 8:17:18 PM

people

What's the purpose of the Newtonsoft.Json.JsonToken.StartConstructor token?

The JsonToken enum in Newtonsoft.Json namespace contains, among others, the entry JsonToken.StartConstructor. I most likely misinterpret the meaning of this token, as I take it...
Jon Skeet
people
quotationmark

Looking at the ParseTests source code, it looks like it's so that you can have JSON like this: { "date": new Date(2017, 2, 10) } ... which isn't actually valid JSON, but may be common in the wild. more 2/10/2017 11:36:55 AM

people

A URI scheme name 'pack' already has a registered custom parser

I am newborn to NUNIT test,facing error as 'A URI scheme name 'pack' already has a registered custom parser'. [SetUp] public void OnTestInitialize() { UriParser.Register(new...
Jon Skeet
people
quotationmark

Well presumably OnTestInitialize is currently being called once per test, but you want UriParser.Register to be called once in total. That's the sort of thing that makes sense to do in a static initializer, which is guaranteed to be run... more 2/10/2017 7:11:49 AM

people

DateTime Formatting on Azure hosted site

so my tech stack is: asp.net core 1.1 hosted on Azure using CSV Helper to read CSVs into a SQL database (in azure). ok so the problem i'm facing is when i'm using CSV helper...
Jon Skeet
people
quotationmark

If you want to make sure CsvHelper always uses one particular culture, you can set it explicitly: csv.Configuration.CultureInfo = auCulture; You should bear in mind, however, that a DateTime doesn't "store" a format - so once you've... more 2/9/2017 2:47:34 PM

people

How to find the most specific types in an arbitrary hierarchy

Let's say we have a collection of types: var types = new[] { typeof(IEnumerable<int>), typeof(ICollection<int>), typeof(Stack<int>), ...
Jon Skeet
people
quotationmark

It seems to me that Type.IsAssignableFrom is your friend here. You want types that aren't assignable from any of the other types in the set: using System; using System.Collections.Generic; using System.Linq; class Program { static... more 2/9/2017 12:17:47 PM

people

loading inner class without loading the enclosing class

I was bit confused when is the inner class (non static) gets loaded by the jvm . Is it dependent on the outer class. or can it be separately loaded without loading the outer...
Jon Skeet
people
quotationmark

Given that an inner class has a field with reference to an instance of the enclosing class, I don't see how it could be loaded without loading the enclosing class. A static nested class may well be different, as that's genuinely... more 2/8/2017 12:01:47 PM

people