Browsing 15589 questions and answers with Jon Skeet

RegisterTemplate type error C# .Net Handlebars

The docs for this library seem straightforward enough, but attempting to register a partial throws a type conversion error: string testname = "myName"; string testbody = @"my...
Jon Skeet
people
quotationmark

The static Handlebars.RegisterTemplate(string, string) method was added in this commit on January 31st 2017. The last NuGet release of Handlebars.Net was in October 2016 - so you don't have access to it yet. Options: Wait for it to be... more 4/27/2017 5:39:29 PM

people

Ignoring strings in LINQ order by clause c#

I have a collection of strings that are as follows: "[Unfinished] Project task 1" "Some other Piece of work to do" "[Continued] [Unfinished] Project task 1" "Project Task...
Jon Skeet
people
quotationmark

It sounds like you should write a method that retrieves "the part of the string which isn't in brackets" (e.g. using regular expressions). Then you can use: var ordered = collection.OrderBy(RemoveTextInBrackets); Your... more 4/26/2017 10:30:23 AM

people

Get enum values via reflection from nested enum in generic class

I need to print out enum values and their corresponding underyling values from certain types i accquire through reflection. This works fine most of the time. However if the enum...
Jon Skeet
people
quotationmark

Construction a type would be a workaround but inacceptable for me, since it would get too complicated. That's the only way of getting values that will behave normally. You can get at the fields of an open type, and the bizarre thing... more 4/26/2017 10:27:48 AM

people

JavaL Different Big Decimal values converted to UTF 8 Strings have the same value

As part of having fun with Avro, I discovered the following: new String(new BigDecimal("1.28").unscaledValue().toByteArray(), Charset.forName("UTF-8")) .equals( new String(new...
Jon Skeet
people
quotationmark

Can someone explain to me what is going on? Yes, you're misusing your data. The result of BigDecimal.toByteArray() is not a UTF-8-encoded representation of a string, so you shouldn't try to convert it to a string that way. Some... more 4/26/2017 7:14:38 AM

people

XElement how do I get descendants of an element into a string

I'm using an XElement object in.Net 3.5 Framework to load the following xml fragment. Example XML: <xmlfragment> <list id="1" value="one" /> <list id="2"...
Jon Skeet
people
quotationmark

As you're using .NET 3.5, there are no particularly easier ways of simplifying this - although if you find yourself needing it frequently, you could always write your own static methods to emulate the new overloads of string.Join. It's... more 4/25/2017 3:59:35 PM

people

Class.getDeclaredMethods() of reflection is returning unwanted values

I have a class A which is a abstract class, class B is concrete and extends A. Calling B.class.getDeclaredMethods() returns class A's method signatures in addition to class B's...
Jon Skeet
people
quotationmark

The oddity isn't in getDeclaredMethods() - it's in the class file for B, with a body that just calls super.foo(). I don't fully understand it, but it appears to be related to foo() being a public method declared in a package-private... more 4/25/2017 10:22:48 AM

people

Java Time Zone code help in GMT

Can you help in understanding this code. Looks like it is getting timezone As an off-set from GMT in hours. But not sure... what is the consideration for DST in the code...
Jon Skeet
people
quotationmark

Firstly, code like this is almost always a mistake. Java provides quite a lot of options when it comes to text formatting for date/time types... I'd recommend using java.time as far as possible. However, in terms of how this code takes... more 4/25/2017 5:56:15 AM

people

How to Calculate 10^5 in Flex

I am new to flex and I am struggling to know how to calculate 10^5 (10 to the power 5). If It was a java code I would have written like this But In this case, I didn't found any...
Jon Skeet
people
quotationmark

I'm not 100% sure whether this link is still relevant or not, but the Adobe Flash ActionScript documentation still has Math.pow: Computes and returns base to the power of pow. more 4/25/2017 5:48:00 AM

people

Collect indexes from list

Is there a linq function in c# which enables you to collect IEnumerables from a specific range of indexes? An example would be var objectArray = new string[] { "Bill",...
Jon Skeet
people
quotationmark

If the original datasource is already accessible by index, such as for a list or an array, you can just use indexArray.Select as Matt showed. If you've got an IEnumerable<T> instead, you can use the Where overload which provides the... more 4/24/2017 4:45:01 PM

people

Is the Left Hand Operand First broken?

according to this here left will be evaluated before right... but I have a project where: int[] df = null; //GetDataFrame() int xIndex = 12; //GetLearningIndex() df[0] = 1 %...
Jon Skeet
people
quotationmark

There's some confusion here... parts of the LHS of the assignment operator are evaluated first. In particular, the expressions df and 0 will be evaluated before GetLearningIndex, but the array element assignment (including index... more 4/24/2017 8:12:35 AM

people