Browsing 15836 questions and answers with Jon Skeet

Unexpected behavior in zip method

I have the following code: [TestMethod()] public void Test_Changed() { var All = repository.GetProducts().Select(c => c.Price).ToList(); var Original = All.ToList(); ...
Jon Skeet
people
quotationmark

Like many LINQ operations, Zip is lazy - your lambda expression is never being executed, because you're calling Zip but never using the results. If you changed your test to do something like: var list = All.Zip(...).ToList(); Then I... more 7/14/2017 1:37:59 PM

people

Current Time of Timezone

I have different timezones and their GMT and DST. Example: TimeZoneId | GMT offset | DST offset | 1. Jan 2010 | 1. Jul...
Jon Skeet
people
quotationmark

The time zone IDs you've given are the ones from the IANA time zone database, aka TZDB (aka Olson, aka tz). They're not supported by .NET (although .NET Core running on Linux/Mac will probably do what you want). My Noda Time project does... more 7/14/2017 6:20:01 AM

people

Casting Causes Different GetTypes

So I don't have an in-depth knowledge of how data is stored in the .NET Framework in terms of custom types, but I was looking for an explanation on how the casting system is...
Jon Skeet
people
quotationmark

The result of the first cast is a different value. It's now a byte not a char. The second cast is a reference conversion. The result is the same set of bits - a reference to the same object - just with a different compile-time type.... more 7/13/2017 10:31:42 AM

people

MSBUILD : error MSB1008: Only one project can be specified. Switch: Studio

private void GetExeFile(string link) { Process compiler = new Process(); compiler.StartInfo.FileName = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe"; ...
Jon Skeet
people
quotationmark

You need to quote the solution filename because it has spaces in: compiler.StartInfo.Arguments = link + @"‪""C:\Users\khan\Documents\Visual Studio 2012\Projects\Calculator\Calculator.sln"" /t:build /r:System.dll /out:sample.exe... more 7/12/2017 10:47:40 AM

people

Dotnet build doesn't work with newcsproj and PackageReference

Reproduce steps: Open Visual Studio 2017, create new class library project, .NET 4.6.1. Add reference to Newtonsoft.Json with Nuget Package Manager. Build project successfully...
Jon Skeet
people
quotationmark

You're using the "old style" msbuild project, which won't work with the dotnet CLI. Replace your whole project file with: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> ... more 7/11/2017 2:00:38 PM

people

Delegate doesn't seem to register 'params'

The params keyword of C# allows equivalence between Array and parameter-list, does it not? Sadly, in my implementation, this isn't the case. private Entities queryType(String...
Jon Skeet
people
quotationmark

The params keyword of C# allows equivalence between Array and parameter-list, does it not? When the C# (or VB) compiler is involved, yes. Not when you're using reflection. The problem is that you're invoking the delegate dynamically... more 7/11/2017 10:51:16 AM

people

Precedence in Java

Unary postfix increment and decrement operators have more preceedence than relational operators according to precedence table, so why in a expression like this (x++ =10) the...
Jon Skeet
people
quotationmark

The operator isn't evaluated first. The ordering is: Evaluate LHS (x++) - the result is the original value of x, then x is incremented Evaluate RHS (10) - the result is 10 Compare the results of the LHS and RHS Here's code to... more 7/11/2017 8:20:46 AM

people

Derived Class using Parent Method

Why can't i access the age method from either class A or B? I thought because it's a protected method, derived class instances should be able to use it? class Program { ...
Jon Skeet
people
quotationmark

Protected means it can be used from code in the derived classes - it doesn't mean it can be used "from the outside" when working with derived classes. The protected modifier can be somewhat tricky, because even a derived class can only... more 7/11/2017 5:46:28 AM

people

LINQ OrderBy based on row values

Lets say we have two tables Parent "DocumentCodes" and Child "Documents". DocumentCodes table have columns DID,DocumentName,PrintOrder and AscOrDesc Documents table have columns...
Jon Skeet
people
quotationmark

The situation is a fairly ugly one, given that two result rows could theoretically be compared which have the same PrintOrder but different AscOrDesc values. It's only the source of the data that's preventing that. I do have a horrible... more 7/10/2017 4:04:49 PM

people

Generic class and simplified constrains?

Lets say I've got a generic interface IFace<T, U>. The T and U can be constrained in some additional way, but I don't think this is relevant to the problem. I'd like to...
Jon Skeet
people
quotationmark

Is this possible, or do I NEED to specify the T and U generic parameters? You need them, I'm afraid. You'll need to have class GenClass<T, TX, TY> where T : IFace<TX, TY> That's assuming you can't create a non-generic... more 7/10/2017 8:10:25 AM

people