Browsing 7239 questions and answers with Jon Skeet

Excluding dates from period using Nodatime

I'm trying to workout the amount of time between two LocalDateTime values and exclude specific dates (in this example, it's bank holidays). var bankHolidays = new[] { new...
Jon Skeet
people
quotationmark

I feel like I'm missing some obvious and there should be an easier method, is there a simpler way to find a period between two dates whilst excluding certain dates? Well, it's relatively easy to count the number of bank holidays... more 11/19/2013 4:47:04 AM

people

Convert hex string back to string

I have a string which has a character I would like to replace. The character has a hex value of 96 and I would like to replace that character with a hex value of 2D. I tried to...
Jon Skeet
people
quotationmark

If you're actually trying to replace U+0096 with U+002D, you can use: text = text.Replace("\u0096", "\u002d"); Note that U+0096 is "start of guarded area" though. If you actually mean "the value that is encoded in Windows 1252 as 96"... more 11/18/2013 10:44:56 PM

people

Working with days which don't start at midnight in NodaTime

I am working on an application with train schedules, where the first train leaves at 0400 while the last train leaves at 0200. The users of this application therefore deal with...
Jon Skeet
people
quotationmark

I would store the actual date/time value. Then for querying, to search for "anything on Wednesday" you'd go from Wednesday 0400 (inclusive) to Thursday 0400 (exclusive). In terms of display, you'd probably be best taking the date, and... more 11/18/2013 4:54:14 PM

people

LINQ to objects performance

I am constructing a LINQ query on a DataSet, it will have a .Where condition, .Distinct and .OrderBy. I was thinking of doing this manually at first, at best I can probably manage...
Jon Skeet
people
quotationmark

Is there anyway to see what LINQ does in the background? Well, you could look at my Edulinq implementation and the accompanying blog posts to get an idea of what's going on in LINQ to Objects. Obviously it's not the real... more 11/18/2013 4:12:52 PM

people

Require parameter naming to prevent ambiguity on same ish looking parameter list

Consider the following definition: class Foo { string Asd; List<int> Qwert; public Foo(string Bar, List<int> Baz = null) { // Set up...
Jon Skeet
people
quotationmark

How can I make the compiler force the invocation with named parameters? You can't, basically. It's just not part of the language. What you can do is make the constructors private, and instead expose static factory methods, which... more 11/18/2013 3:26:01 PM

people

Interface with generic method parameter type in list

I have a HashMap that links specific RequestTypes to separate LinkedLists. The lists consists of an interface with a generic type. I have no problems adding to the lists in the...
Jon Skeet
people
quotationmark

It sounds like you want to constrain your Result type parameter to extend Notification: private HashMap<RequestType, LinkedList<IRequestListener<? extends Notification>>> requestListenerMap = new HashMap<>();... more 11/18/2013 2:46:13 PM

people

Use of try catch for taking care of letters

I have written a program that will emulate how a cash register works. I would need some help with how to make the program take care of, if for example the user enters letters...
Jon Skeet
people
quotationmark

Firstly - and more importantly - for currency values, you should be using decimal rather than double. Decimal floating point numbers are more appropriate for monetary values, which are exactly represented in decimal - whereas binary... more 11/18/2013 2:38:29 PM

people

Represent Enum values as String

I have this Enum Public Enum HotkeyModifiers As Short SHIFT = 1 CONTROL = 2 ALT = 4 NONE = 0 End Enum So 6 is equals to ALT+CONTROL, so when I do this: ...
Jon Skeet
people
quotationmark

You need to decorate your enum with FlagsAttribute. <Flags> Public Enum HotkeyModifiers As Short SHIFT = 1 CONTROL = 2 ALT = 4 NONE = 0 End Enum That affects the behaviour of both ToString and parsing. more 11/18/2013 1:47:27 PM

people

the if statement help{noob}

first of all i just want to say that i am a noob when it comes to c# programming., also i think this is an if statement situation, i could be wrong I have google my query and...
Jon Skeet
people
quotationmark

It sounds like you're after something as simple as: Console.WriteLine("{0} + {1} = {2}", x, y, x + y); if (x + y > 10) { Console.WriteLine("TRust too large"); } An if statement is basically just a condition, with some code to... more 11/18/2013 12:39:04 PM

people

How to get SQL Server datetime value as it is in 24 hours in C#

I am developing an app in VS2010 c# to fetch a single row data from SQLServer and insert it to MySQL. I have a table with column name Date_Time containing date and time in 24...
Jon Skeet
people
quotationmark

I have a table with column name Date_Time containing date and time in 24 hrs. format No, you have a table with a column type of DateTime. The values don't inherently have any format - they just happen to be displayed one way in your... more 11/18/2013 5:13:43 AM

people