Browsing 15711 questions and answers with Jon Skeet

an expression tree lambda may not contain a null propagating operator

Question: The line price = co?.price ?? 0, in the following code gives me the above error. but if I remove ? from co.? it works fine. I was trying to follow this MSDN example...
Jon Skeet
people
quotationmark

The example you were quoting from uses LINQ to Objects, where the implicit lambda expressions in the query are converted into delegates... whereas you're using EF or similar, with IQueryable<T> queryies, where the lambda expressions... more 6/21/2017 4:19:47 PM

people

How to remove ambiguous method call in c#

Here I have a simple scenario with two methods where I get an ambiguous invocation from one another: This is a my code: public IEnumerable<JobsViewModel>...
Jon Skeet
people
quotationmark

The only way to do this would be to fill in the optional parameter with a value of the appropriate type, so that the compiler knows which overload to pick. For example: public IEnumerable<JobsViewModel> GetJobsViewModels( Guid... more 6/21/2017 10:31:49 AM

people

System.Net.WebException remote name could not be resolved 'http'

I am using System.Net.HttpWebRequest to make a request to a server by setting the proxy property of the object as: webRequest.Proxy = New WebProxy("10.x.x.x", port); it works...
Jon Skeet
people
quotationmark

You're calling the WebProxy(string, int) constructor - where the string is meant to be a host name, not a URI. You should call the WebProxy(string) constructor, at which point the string is a URI. If you need to specify a non-default... more 6/21/2017 7:26:26 AM

people

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