Browsing 7239 questions and answers with Jon Skeet

What is bit 6 of a character?

Here the documentation from Escape Sequences PHP.net (encoding the non-printing character (i.e SUB) to \cx for search pattern): The precise effect of "\cx" is as follows: if...
Jon Skeet
people
quotationmark

But isn't it should be bit 7 be inverted,not 6? And what hex 40(1000000) doing here? These two questions are related to each other. The documentation is indicating the value that they mean by "bit 6". Basically, they're using the... more 2/18/2016 11:51:44 AM

people

Nodatime Formatting Long Date Pattern From A Specific Culture But Using Month Names From Another Culture

In Noda Time, I want to format a Long Date Pattern using a specific culture but using month names and day names from another culture. My initial code is: var dtfi =...
Jon Skeet
people
quotationmark

Yes, this is a problem with the architecture of IFormatProvider, basically - which we don't handle as well as we might. Both DateTimeFormatInfo and CultureInfo implement IFormatProvider, but in order to perform formatting in some cases, we... more 2/18/2016 7:15:19 AM

people

Setting a default value for property that is mutable in C#

I have a property public int active { get; set; } That in my db has a default value of 1. I would like to have this property default to 1 if not otherwise specified public...
Jon Skeet
people
quotationmark

Just set it in the constructor: public partial class Test { public int Id { get; set; } public string Test1 { get; set; } public int Active { get; set; } public Test() { Active = 1; } } I think that's... more 2/17/2016 4:38:57 PM

people

NumberFormatException while multiplying

I'm trying to 'Run Configurations' in Eclipse. When I pass something like '1 + 2', or '123 - 321', or '123 / 321' it works well. The problem appears when I try to do...
Jon Skeet
people
quotationmark

The problem is how you're invoking the program. If you run: java Calculator 5 * 10 then in some command shells, the * will be automatically expanded to all filenames in the current directory. You should be able to fix this with quoting,... more 2/17/2016 9:32:41 AM

people

Order of creation of instances

I have the following classes: class X { int x = 100; } class Y:X { int y = 100; } and the following decompiled code: class X { int32 x; public void X() ...
Jon Skeet
people
quotationmark

Maybe does it exist only one object? Yes, exactly. A single object is created, which immediately is of the type specified (Y in this case). All fields (across the inheritance hierarchy) are initially set to the default values of their... more 2/17/2016 9:24:32 AM

people

Get list of subscribers to Timer.Elapsed event

I'm trying to find a way to determine the number of subscribers there are to a timer's elapsed event. From my searches, it seems like I should use GetInvocationList(). However...
Jon Skeet
people
quotationmark

You can call GetInvocationList on a delegate, but an event isn't a delegate - an event is just a consistent way of exposing "subscribe" and "unsubscribe" operations, and a simple way of implementing those operations (using... more 2/16/2016 4:13:07 PM

people

Dictionary from other dictionary grouping by object value field using linq

I have a Dictionary<ulong,Terminal> called TeminalDictionary in my program, where Terminal has the next props: public class Terminal { public string TAC { get; set; } ...
Jon Skeet
people
quotationmark

You just need to provide the key in the new dictionary as well, which in your case is the key of the group. Given that you don't appear to need the keys within the original dictionary, I'd write this as: var pieDictionary =... more 2/16/2016 11:26:15 AM

people

Math from class isn't carrying in to object

I have to make a program that has the Circle class which calculates the area and circumference of a circle by accepting a parameter for r from a new circle object in main. I fed...
Jon Skeet
people
quotationmark

Your area and circumference variables are only being set if you call the appropriate calculation methods (calcArea and calcCircumference). You're not calling them, so they have the default values of 0. You could fix this in your main... more 2/16/2016 7:21:10 AM

people

Difference between String, FormattableString, IFormattable

FormattableString has been Introduced in C# 6.0. As we can use same string formatting using string object why is there need of using FormattableString or IFormattable. Whats...
Jon Skeet
people
quotationmark

FormattableString is a new type in .NET 4.6, and the compiler will only use it if you try to use it. In other words, the type of an interpolated string literal is normally string - built with string.Format - but can be FormattableString... more 2/16/2016 7:09:58 AM

people

The getValue() method is overridden in two ways. Which one is correct?

My problem with the following example is that I have read that if you override a function, the return type cannot be changed unless you are overriding in a descendant object, in...
Jon Skeet
people
quotationmark

The second is fine, because of this rule in JLS 8.4.8.3: If a method declaration d1 with return type R1 overrides or hides the declaration of another method d2 with return type R2, then d1 must be return-type-substitutable (ยง8.4.5) for... more 2/15/2016 4:51:58 PM

people