Browsing 7239 questions and answers with Jon Skeet

Using "is" keyword with "null" keyword c# 7.0

Recently i find out, that the following code compiles and works as expected in VS2017. But i can't find any topic/documentation on this. So i'm curious is it legit to use this...
Jon Skeet
people
quotationmark

Yes, it's entirely valid. This uses the pattern matching feature of C# 7, which is available with is expressions and switch/case statements. (The fact that it requires C# 7 is why it isn't working for you in VS2015.) For example: // Type... more 4/8/2017 2:19:42 PM

people

C# MySQL Order By Returns 1

I'm trying to get the last row of a table using C# but it doesn't seem to be working, this is my code: MySqlConnection cnnGetID = new...
Jon Skeet
people
quotationmark

The value this returns is -1 while it should be returning 59. No, it's behaving exactly as documented by IDbCommand.ExecuteNonQuery: For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by... more 4/8/2017 8:59:57 AM

people

Get the between time range from list of dates

I am currently want to get the date range (between time range) from the list of dates. For example: The time now is 2017-04-08 18:00 And I got these from and to...
Jon Skeet
people
quotationmark

I would start by converting everything into a more useful object model: Get rid of all the strings (i.e. convert from strings to something more useful early on) Instead of having two collections, create a new type indicating "a date/time... more 4/8/2017 7:37:10 AM

people

How is the Australia/Melbourne and Australia/Victoria treated in NodaTime?

I have started using NodaTime and noticed a little problem. Based on the wiki page https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Australia/Melbourne should have...
Jon Skeet
people
quotationmark

Where to look for source of truth? The IANA time zone database is the best source I'm aware of, and that's what Noda Time uses. If you want to see what the results of that are and have been over time, the tzvalidate page has a list... more 4/7/2017 12:46:22 PM

people

the type name text does not exist in the type xmlnodetype

I am trying to read a certain section from an xml file in C#. I tried using this code here but I get a compiler error under the Text in XmlNodeType.Text but the weird thing is it...
Jon Skeet
people
quotationmark

XmlNodeType is an enum. XmlNodeType.Text is a value, not a type, but you're trying to use it as the type of the aa variable. Furthermore ReaderInnerXml() returns a string, so it's not clear how you expect to iterate over it. Do you have... more 4/7/2017 8:52:37 AM

people

NodaTime UnparsableValueException due to usage of "Z" in pattern

I am exchanging JSON messages between Java and C# (and vice-versa). In Java I use a java.time.Instant (JSR-310) to represent a point in time on the global timeline. In order to...
Jon Skeet
people
quotationmark

That's like asking for 2017-04-28T19:54:44 to be parsed as a LocalDate - there's extra information that we'd silently be dropping. Fundamentally, your conversion from Instant to String in Java is "adding" information which isn't really... more 4/7/2017 8:48:24 AM

people

Why a char default value is not displayed on console?

I wanted to know what will it get displayed on console when you try to print a char default value. But unfortunately, I can't see anything on the console. why? I should be able to...
Jon Skeet
people
quotationmark

There's a big difference between the character for "the decimal digit 0" which is U+0030... and U+0000, the null character, which is a control character and so has no printed output. You're printing out the latter, so I wouldn't expect to... more 4/6/2017 10:08:27 PM

people

Creating a ServiceAccountCredential for a user from a Systems account

I use the following code to act on behalf of a user through a System-login (domain-wide authenticated). The only example I found which accomplishes this uses reflection to set the...
Jon Skeet
people
quotationmark

Here's how I'd do it, setting both the scopes and the new user at the same time via the ServiceAccountCredential.Initializer: ServiceAccountCredential original = (ServiceAccountCredential) ... more 4/6/2017 1:18:18 PM

people

Get value from table as a reference

In c++ it`s possible to do it by reference (&) or pointer (*). In C# there is "ref". How to get value from table and change it by reference to it? namespace Rextester { ...
Jon Skeet
people
quotationmark

This has only become feasible in C# 7, using ref locals: public class Program { public static void Main(string[] args) { int[] t = {1, 2, 3}; ref int a = ref t[0]; a += 10; ... more 4/6/2017 12:59:35 PM

people

Indexer that points to item in struct array don't work

I have a class called Surface, in this class i have an array of type struct Color. public class Surface { private Color[,] pixels; public Color this[int x, int y] { ...
Jon Skeet
people
quotationmark

How can i solve this problem? Well you could avoid creating mutable structs and exposing public fields, to start with. That's where the problem is coming from. Your code is effectively: Color tmp = mySurface[x, y]; // Take a copy... more 4/6/2017 12:10:38 PM

people