Browsing 7239 questions and answers with Jon Skeet

In a class, what is the difference between instance variable and variable without modifier in c#

In the following code: public class Foo { private object first; object second; public void Bar() { first = "1234"; second = "1234"; } } What is the...
Jon Skeet
people
quotationmark

What is the difference between two declaration? Nothing, as this is C#. In general, if you declare anything in C# without using access modifiers, it's equivalent to using the most private valid access modifier for that place1. So... more 5/1/2017 6:42:28 PM

people

HOUR_OF_DAY sets the same hour for value 0 and 1

I have a tricky (at least for me) question with java time zones. I will start with an example that works as expected: TimeZone tz = TimeZone.getDefault(); SimpleDateFormat...
Jon Skeet
people
quotationmark

Your machine has an old version of time zone data, in which Egypt would have put the clocks forward at midnight local time at the start of April 28th 2017. Therefore 12:31am wouldn't have existed, and Java is skipping forward by an hour... more 4/28/2017 3:53:08 PM

people

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 unwanted behavior

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