Browsing 7239 questions and answers with Jon Skeet

Convert DateTime with DateTimeKind.Unspecified from utc to local

I have a database where all dates are UTC, and the driver always sends me DateTime objects with DateTimeKind.Unspecified. I want to assume they are in UTC and convert to local...
Jon Skeet
people
quotationmark

If you're definitely using Noda Time and want a ZonedDateTime, you could "tell" Noda Time that you've really got a UTC value, then convert it: var zoned = LocalDateTime.FromDateTime(utcDate) ... more 1/15/2017 2:40:50 PM

people

Casting object instance to actual type

I send several different kinds of package classes, which I serialize and send over the network. All packages extend the AbstractPackage: public abstract class AbstactPackage()...
Jon Skeet
people
quotationmark

You could use a dictionary from the type to a delegate to call when you receive a package of that type. So for example: class PackageReader { private static readonly Dictionary<Type, Action<AbstractPackage>>... more 1/14/2017 1:17:13 AM

people

BCL and FCL both are NameSpaces?

I need a clarity regarding class libraries. Base Class Libraries and Framework Class Libraries both are comes under namespaces-I mean can we call both are namespaces? if not which...
Jon Skeet
people
quotationmark

No, they're not namespaces. A namespace is something like System, System.IO or System.Collections.Generic. The libraries contain types that are in namespaces, but the libraries aren't namespaces themselves.  more 1/13/2017 12:33:32 PM

people

When is assignment to a ref argument effective in C#?

Suppose a method is changing the value of an argument passed by reference. Is the effect of such operation immediately visible across the application or only after the method...
Jon Skeet
people
quotationmark

Is the effect of such operation immediately visible across the application or only after the method returns? It's immediately visible - because basically, what you end up passing is the variable itself, not the variable's value.... more 1/11/2017 4:42:04 PM

people

What effect does including async in signature (without await in body) have on program flow?

General question I've just tracked down a strange behaviour to the the absence of an async modifier in the signature of a method. With it, I get the expected behaviour, but...
Jon Skeet
people
quotationmark

My question is: what is async really doing when there isn't an await? In terms of observable behaviour: The code will still run synchronously, as the warning says The result (including any exception thrown) will be wrapped up in a... more 1/11/2017 2:44:56 PM

people

One method accepting different parameters

Using FW 4.5.1 I have a method: void DoSomething(string s) I want to allow the function to accept int as well, but under the same parameter s. That means I want to write: void...
Jon Skeet
people
quotationmark

Three options for you to consider, depending on what you're actually trying to achieve: Use overloads public void DoSomething(int s) { ... } public void DoSomething(string s) { ... } This will only accept int and string - which could... more 1/10/2017 2:17:07 PM

people

XNamespace as additional attribute, why

I want to achieve this: <?xml version="1.0" encoding="utf-8"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> ...
Jon Skeet
people
quotationmark

You're confusing a namespace alias (which you want to be xdt) with the namespace URI. You want to put the elements in the right namespace (by URI) but specify an xmlns attribute in the root element with the alias you want: using... more 1/9/2017 10:16:44 PM

people

List<T> Concatenation dynamically

I am trying to concate List<> as follows- List<Student> finalList = new List<Student>(); var sortedDict = dictOfList.OrderBy(k => k.Key); foreach...
Jon Skeet
people
quotationmark

Other answers have explained why Concat isn't helping you - but they've all kept your original loop. There's no need for that - LINQ has you covered: List<Student> finalList = dictOfList.OrderBy(k => k.Key) ... more 1/9/2017 8:50:36 AM

people

Variant and open generics IReadOnlyList

I'm trying to understand why a specific behavior regarding variant and generics in c# does not compile. class Matrix<TLine> where TLine : ILine { TLine[] _lines; ...
Jon Skeet
people
quotationmark

You just need to add the class constraint to TLine: class Matrix<TLine> where TLine : class, ILine This will ensure that TLine is a reference type - which then allows generic variance to work. Variance only works for reference... more 1/6/2017 10:45:05 AM

people

LINQ Fetch items from list starting from specific index

With the help of LINQ, I need to fetch items from a list based on a condition. For that it should consider items only from (provided index - 3) to provided index...
Jon Skeet
people
quotationmark

It sounds like you just want a mix of Skip and Take, filtering with Where: var query = list.Skip(index - 3) // Start at appropriate index .Take(3) // Only consider the next three values ... more 1/6/2017 10:04:56 AM

people