Browsing 7239 questions and answers with Jon Skeet

How to know if current time is between two timespans?

I have two time spans like so: TimeSpan Starttime : 16:37:00 TimeSpan EndTime: 17:37:00 current time: DateTime currentDate = DateTime.Now; TimeSpan now =...
Jon Skeet
people
quotationmark

You can just use: if (startTime < now && now < endTime) Note that: This doesn't check the date; doesn't look like that's an issue here Depending on why you're doing this, you may want to consider intervals such as... more 6/20/2016 3:24:56 PM

people

Can I host a .net web application (blog) on google app engine? Are there any tutorials on how to do it?

I am currently going through a tutorial for deploying an application on google app engine. The tutorial however uses python. I want to know if it can be done for C#. If not, is...
Jon Skeet
people
quotationmark

No, Google App Engine "standard" environment doesn't support .NET. The "flexible" environment (currently in beta) supports custom runtimes, with the proviso that it'll be running on a Docker container. So if you are able to get your web... more 6/20/2016 3:04:20 PM

people

Can I use quote marks in an XML documentation comment?

When writing an XML documentation comment in a C# source file, do I need to replace " with &quot;? This question discusses how to replace characters, but does not establish...
Jon Skeet
people
quotationmark

No, just like normal XML, you only need to escape the quotes when they would otherwise have a special meaning. So if your XML documentation contains an attribute and you want a double quote in the attribute value, then you'd either use an... more 6/20/2016 10:34:16 AM

people

Cannot determine where the base constructor is called, signing the event

So, here is my code. The output is 2255. But I caanot understand why method in class A will be executed, for we haven't signed the event on it, as we haven't created an instance...
Jon Skeet
people
quotationmark

As you haven't declared any constructors in B, the compiler has provided a default constructor - it's as if you'd written: public class B { public B() : base() { } // Rest of class here } So when you call new B(), the A... more 6/20/2016 6:06:01 AM

people

Cast from a delegate to a func

I have a project in school where my teacher is asking us to add a delegate to a List of Funcs. The code I have below is having issues in the AddDel method. Intellisense is...
Jon Skeet
people
quotationmark

Basically, you shouldn't declare your own delegate here at all. There are no conversions between delegate types like this. You want a Func<int, double, char, string, string>, so declare one: Func<int, double, char, string,... more 6/17/2016 8:32:31 PM

people

Why does the compiler choose override with IEnumerable over IEnumerable<T>?

Consider the following two extension methods: using System; using System.Collections.Generic; using System.Linq; public static class Extensions { public static bool...
Jon Skeet
people
quotationmark

My question is, why does the compiler choose my Contains() method with non-generic IEnumerable argument over Enumerable.Contains<T>() with IEnumerable<T> argument? Because it's found in the same namespace that contains the... more 6/17/2016 8:26:36 PM

people

Converting between unkown derived types at runtime

Lets say I have an abstract base class used for polymorphism and I like to write a method to convert one derived type to another, but I don't know either of the derived types at...
Jon Skeet
people
quotationmark

It sounds like you're asking for reflection over user-defined conversion operators. You can get at those with reflection by asking for public static methods and filtering to ones called op_explicit or op_implicit, with the right parameter... more 6/17/2016 5:35:24 AM

people

How to get object properties from IEnumerable<object[]> using LINQ c#

I have one List with collection of object arrays.I am using following code to collect all EmployeeIDs List<string> employeeIds= new List<string>(); var employeeFields...
Jon Skeet
people
quotationmark

You can use SelectMany and OfType to do this in one go: var employeeIds = employees.Items .Select(c => c.EmployeeFields) // Select the fields per employee .SelectMany(fields => fields) // Flatten to a single... more 6/16/2016 9:12:29 AM

people

Convert string to float without Decimal Point and Exponential values

I have a scenario where I receive Phone Numbers and I have to save those numbers to database. The Phone Number column in DB is of type float. But I am receiving phone numbers as...
Jon Skeet
people
quotationmark

The first problem is that choosing a floating point numeric type to represent a phone number is a terrible idea, which is likely to cause you problems all over the place. I would urge you to work out just how much effort it would take to... more 6/16/2016 8:55:03 AM

people

What is the encoding used for Khmer Language

I want to know what encoding is used for Khmer Language (Official language of Cambodia). Is it UTF-8 or UTF-16.
Jon Skeet
people
quotationmark

A language doesn't have an encoding. What it might have is a set of characters that are commonly used when writing in that language. Some encodings only support subsets of Unicode, but both UTF-8 and UTF-16 can encode all Unicode... more 6/16/2016 8:43:56 AM

people