Browsing 7239 questions and answers with Jon Skeet

How to get UTF 8 codepoints of C# string?

I have a German string in C# string s = "MenĂ¼"; I would like to get UTF-8 codepoints: expected result: \x4D\x65\x6E\xC3\xBC The expected result has been verified via online...
Jon Skeet
people
quotationmark

There's no such thing as "UTF-8 codepoints" - there are UTF-8 code units, or Unicode code points. In the string MenĂ¼, there are 4 code points: U+004D U+0065 U+006E U+00FC For BMP characters (i.e. those in the range U+0000 to U+FFFF)... more 8/10/2016 11:02:20 AM

people

Java: How does a method operate on objects of unknown type?

Consider, the following three Java classes in three different packages: User.java package user; public class User { String name; public String getName() { ...
Jon Skeet
people
quotationmark

The only purpose of an import statement is to allow you to use a type (or a method etc, for import static) without fully-specifying the name. It doesn't make the type available - it just makes it available by short name. In this case, the... more 8/10/2016 7:56:13 AM

people

Is there a way to detect if string concatenation have been used?

In our datalayer, I want to discourage the use of string concatenation and make people use parameters instead. But as far as I know, there is no way to see if a parameter is a...
Jon Skeet
people
quotationmark

If your executeQuery method only has a parameter of FormattableString, then you should be fine already - there's no conversion from string to FormattableString. For example: using System; class Program { static void Main(string[]... more 8/10/2016 7:18:39 AM

people

How does Bit wise operators work with Enums

enum WeekDays { Monday = 0, Tuesday = 1, Wednesday = 2, Thursday = 3, Friday = 4, Saturday = 5, Sunday = 6 } private void button4_Click(object sender,...
Jon Skeet
people
quotationmark

Basically, your enum isn't suitable for use with bitwise operations. To be appropriate for bitwise operations, each distinct value should be represented by a different bit - whereas you've just got the numbers 0-6. The reason you're... more 8/10/2016 6:40:04 AM

people

How can I emulate "typeof (T)" using the System.Linq.Expressions API?

I'm trying to create a method that will create a DataTable from a list of objects using the System.Linq.Expressions API, but I can't figure out how to generate the following IL...
Jon Skeet
people
quotationmark

Just use Expression.Constant and pass in typeof(int) as the value: var expression = Expression.Constant(typeof(int), typeof(Type)); That's what happens when you use typeof within a lambda expression,... more 8/9/2016 11:30:30 PM

people

Using Calendar in while loop?

The code below does what I want except for the very last output. Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(1986, 8, 20); int year =...
Jon Skeet
people
quotationmark

Your loop is performing the add after it's performing the check. So you probably just want: while (year >= cal.get(Calendar.YEAR)) { System.out.println(sdf.format(cal.getTime())); cal.add(Calendar.DAY_OF_MONTH, 7); } That... more 8/9/2016 10:16:00 PM

people

gloud java. PERMISSION_DENIED: Google Cloud Pub/Sub API (Experimental)

I use gloud-java experimental library. After update today, error occurred. Run example from library local (This error is automatically appeared in the google cloud flexible...
Jon Skeet
people
quotationmark

(Caveat: I work on the team building the equivalent library for .NET. That means I know a certain amount of the infrastructure involved, but I don't know any Java-specific details.) If you're just trying to use the PubSub v1 API, I... more 8/9/2016 9:48:24 PM

people

Best way to convert between noda time LocalDate and Datetime?

I am using both the native Datetime and the Noda Time library LocalDate in the project. The LocalDate is mainly used for calculation whereas Datetime is used in rest of the...
Jon Skeet
people
quotationmark

The simplest approach would be to convert the DateTime to a LocalDateTime and take the Date part: var date = LocalDateTime.FromDateTime(dateTime).Date; I'd expect that to be more efficient than obtaining the year, month and day from... more 8/9/2016 9:24:02 PM

people

Function to return a function that returns a function, etc

Is it possible to define a function in a way that it basically returns itself as a delegate? For example, if this was valid syntax: public class Scrub { public NotNull...
Jon Skeet
people
quotationmark

Well yes, you can, with your own delegate declaration: delegate SelfReturner<T> SelfReturner<T>(T value, string name); static SelfReturner<T> NotNull<T>(T value, string name) { if (value == null) throw new... more 8/2/2016 9:41:55 PM

people

Deserializing JSON with unknown object names

I'm trying to deserialize a JSON response from an API. The JSON looks like this (MAC addresses and location are altered): { "body" : [{ "_id" : "da:87:54:26:53:97", ...
Jon Skeet
people
quotationmark

It looks like you should be able to just get rid of your Measures class. Instead, put the dictionary straight into your Body class: public class Body { public string _id { get; set; } public Place place { get; set; } public... more 7/31/2016 9:37:58 PM

people