Browsing 7239 questions and answers with Jon Skeet

NodaTime update manual tz db

there is a section "Using a NodaZoneData file" on how to include and load the tz data from a NodaZoneData file. the code section show the following IDateTimeZoneProvider...
Jon Skeet
people
quotationmark

How do you set the created provider to the NodaTime library in order to use it as a default? Very few things in Noda Time use any provider as the default. (Similarly we don't use the system time zone by default, and try to avoid... more 9/2/2016 6:23:50 AM

people

Can I increase a c# character's value by addition?

For instance, I want to do something like the following: char output = 'A' + 1; getting output of 'B' However, simply trying what I have above gives a casting error.
Jon Skeet
people
quotationmark

Yes, the binary + operator isn't defined on char, so you end up with implicit conversions to int. You can use a pre/post-increment operator: char x = 'A'; x++; ... because the ++ operator is defined for char. But otherwise, you need a... more 9/1/2016 5:13:34 PM

people

Disabling and enabling a timer causes a second instance?

I have a Start and Stop button on a form that start and stop a repeating SQL query which sends data to a pubnub channel. When I fire up the form and click start, I see what I...
Jon Skeet
people
quotationmark

No, you have a single timer - but you're adding an event handler to it every time you click start: query1Timer.Elapsed += new ElapsedEventHandler(doQuery1); Just move that line into wherever you construct the timer, so it only gets... more 8/31/2016 1:56:39 PM

people

Reading content length of website

I am trying to get the content length of the web page. example http://www.google.com. I am using c# and below is the code I used and does not give me correct length or does it....
Jon Skeet
people
quotationmark

responseLength is -1 allways but result.Length has some value, is that correct? Well it may be for some web sites (or some responses in some web sites) - in other cases, you'll see a non-negative value for responseLength. All you're... more 8/31/2016 1:27:50 PM

people

Why is the "Select" of a Method Syntax is in another parenthesis?

var sample = db.Database.OrderByDescending(x => x.RecordId).Select(y => y.RecordId).FirstOrDefault(); I don't know if my title is correct / right. Just want to ask why...
Jon Skeet
people
quotationmark

In your first example, you're using "regular" C# syntax to call a bunch of extension methods: var sample = db.Database .OrderByDescending(x => x.RecordId) .Select(y => y.RecordId) ... more 8/31/2016 8:55:00 AM

people

Method overloading and inheritance

I have the following classes: public class BaseRepository { public virtual void Delete(int id) { Console.WriteLine("Delete by id in BaseRepository"); ...
Jon Skeet
people
quotationmark

Basically, the way method invocation works in C# is that the compiler looks at the most derived class first, and sees whether any newly declared methods (not including overrides) are applicable for the arguments for the call. If there's at... more 8/30/2016 5:38:21 PM

people

Prefix and Postfix operator overloading in C#

The following code has a runtime issue with unexpected references made by assignment of postfix/prefix increment statement as shown in the code bellow. Also can anyone please...
Jon Skeet
people
quotationmark

Basically, you've misunderstood how this line works: Test obj2 = ++obj; If you think of using your operator as a method, that's like saying: obj = Test.operator++(obj); obj2 = obj; So yes, you end up with obj and obj2 being the same... more 8/30/2016 10:14:23 AM

people

Is this the proper way to convert between time zones in Nodatime?

The goal is to create a function that converts a time from one timezone to another properly using Nodatime. I'm not just looking for feedback on whether the result appears...
Jon Skeet
people
quotationmark

I would stick to Noda Time types as far as possible (and .NET naming conventions). The conversion between zones should be done with ZonedDateTime.WithZone - which means you're really asking about converting to and from ZonedDateTime. If... more 8/30/2016 7:07:55 AM

people

ParallelOptions.CancellationToken seems useless

One of the members of the ParallelOptions is CancellationToken, the value of which is meant to be accessed within the lambda function of Parallel.ForEach. Using it requires...
Jon Skeet
people
quotationmark

If you tell Parallel.ForEach about the CancellationToken, it can stop processing when the token is cancelled. You may not want to throw an exception from your loop - you may just want to ignore the cancellation token yourself, and just... more 8/28/2016 4:12:31 PM

people

IEnumerable.Take(0) on File.ReadLines seems not to dispose/close the File handle

I have a function which Skips n lines of code and Takes y lines from a given file using File.ReadLines with Skip and Take combination. When I try to open the file given by...
Jon Skeet
people
quotationmark

This is basically a bug in File.ReadLines, not Take. ReadLines returns an IEnumerable<T>, which should logically be lazy, but it eagerly opens the file. Unless you actually iterate over the return value, you have nothing to... more 8/25/2016 10:34:20 AM

people