Browsing 7239 questions and answers with Jon Skeet

netcore 1.0.1 missing .NET v4.0.0.0 but using v5.6

I use netcore 1.0.1 and want to open a MySqlConnection. if I use connection.Open() I get the error: The type "DbConnection" is defined in a net referenced Assembly. Add a...
Jon Skeet
people
quotationmark

imports doesn't do what I suspect you think it does - it doesn't actually import anything, but it says "When you're trying to resolve a package, if it doesn't support my actual target framework, pretend that I'm targeting these... more 6/20/2017 7:08:42 AM

people

C# DateTime Constructor Call

So, I have this program that has a constructor with the inputs as DateTime. But whenever I try to create the object of that Class, and pass the DateTime as argument, there is an...
Jon Skeet
people
quotationmark

Well yes - you're trying to pass three integer arguments to the constructor, but it accepts a DateTime value. You're not currently creating a DateTime value. All you need to do is change your constructor call to: var myprogram = new... more 6/20/2017 6:19:29 AM

people

LINQ Count returning 1 instead of zero for an empty group

I've got this SQL query: SELECT oy.ownerId, oy.Year, COUNT(doc.Id) as docCount FROM aavabruf.owneryears oy left join vastdocuments doc on oy.ownerId = doc.Ownerid and oy.Year...
Jon Skeet
people
quotationmark

The simplest approach is to count non-null values: g.Count(x => x != null) I'd suggest moving the ordering after the select so that you can avoid repeating yourself: select new { g.Key.OwnerId, g.Key.Year, DocCount = g.Count(x =>... more 6/19/2017 4:35:48 PM

people

stopwatch in C# using DateTime and TimeSpan

I write a class called stopwatch and their two method(Start() and Stop())in it. Every time I Start and Stop,I should get the TimeSpan for the interval. But every time I run it, I...
Jon Skeet
people
quotationmark

You're creating a new instance of Stopwatch on each iteration - which means that _running will always be false when you call Stop. In addition: You should be using DateTime.UtcNow instead of DateTime.Now, otherwise you'll see a "change"... more 6/18/2017 4:45:09 PM

people

Create Func<Type> from TypeInfo and MethodInfo

I'm curious whether it's possible to create a delegate while having only the type at hand. Something like this: var concreteType = DiscoverTypeInRuntime(); var methodName =...
Jon Skeet
people
quotationmark

You can create such a delegate - but you'll only be able to refer to it as a Delegate because you don't know the actual type at compile-time. It requires creating the appropriate delegate type from Func<T> using MakeGenericType.... more 6/18/2017 7:39:47 AM

people

Noda Time Instant to CET

I'm using the Noda Time libarary (v 2.0.3) for date time handling in a .net core project. However; I'm having some issues converting an instant to a CET date-time. I'm fairly new...
Jon Skeet
people
quotationmark

The Zone line of the europe file in the IANA time zone database contains this single line for the CET zone ID: Zone CET 1:00 C-Eur CE%sT Then the end recurrence of the C-Eur rule is this pair of lines: Rule C-Eur 1981 ... more 6/17/2017 8:55:50 PM

people

C# convert value of variable to variable

class Program { struct St_test { public string f_name; public string l_name; public int age; public string email; } static void...
Jon Skeet
people
quotationmark

You can't (easily, anyway) access variables by name like that - but there's a much better solution, which is to create a collection of some kind - an array or a list, for example. I would suggest: Changing your St_test struct: Make it... more 6/17/2017 9:01:07 AM

people

OffsetTime in NodaTime

I'm looking for some kind of OffsetTime support in NodaTime, but am not seeing anything. I am receiving data in a format such as "17:13:00+10:00". I am to treat this as a time...
Jon Skeet
people
quotationmark

Update: this will now be in Noda Time 2.3. No, there isn't anything representing this in Noda Time. It's a pretty odd kind of value, as in at least many time zones, the offset will vary over the year. I understand that sometimes we need... more 6/13/2017 8:08:50 PM

people

Why are two hours added to my time

I'm struggling with time parsing. My input is a time string ending in "Z". I would expect that to be UTC. When I parse that string two hours are added to the result. I do not know...
Jon Skeet
people
quotationmark

By default, DateTime.Parse converts to a "kind" of Local. (Print out outTime.Kind to verify that.) So it understands that the source is universal - but it's adjusting it to system local time. Note that culture has nothing to do with time... more 6/13/2017 6:31:39 PM

people

MessageBox doesn't show all given string

I have a c# program and am trying to call a messageBox with a specific string(normal string, nothing special), And when reaching a variable to concatenate with the string, it...
Jon Skeet
people
quotationmark

The Win32 GUI libraries terminate strings if they find a \0 character (U+0000, Unicode "null") in them. For example, if you had: MessageBox.Show("First part\0Second part"); then only First part would be displayed. There are at least... more 6/12/2017 5:54:51 PM

people