Browsing 7239 questions and answers with Jon Skeet

Why is the date format different for the same culture on different computers or OS?

I have problem with date formate while hosting site which is developed using C# .net MVC . In my development machine(OS:Windows 7, .net Framework 4.5) date formate for...
Jon Skeet
people
quotationmark

Why format is different in different machine for same culture? Because formats are updated over time, in different OS releases and in patches/hotfixes. .NET is fetching the format from the OS (I believe, anyway), so it's the OS that's... more 7/18/2017 8:55:16 AM

people

DynamicInvoke throws Parameter count mismatch

I'm lost and feel I may be going crazy. In the below code, TestGetCountry() works just fine but TestGetState() throws the "Parameter count mismatch" exception. I'm lost as to why...
Jon Skeet
people
quotationmark

string[] is convertible to object, so this line: string actual = (string) action.DynamicInvoke(args); ... is invoking the delegate with two arguments. You want this: string actual = (string) action.DynamicInvoke((object) args); ...... more 7/17/2017 4:31:59 PM

people

Limit inheritance of intermediate abstract class

I have an abstract class, CreatureBehaviour, that provides a TakeTurn method. The goal of this is to decide what the creature should do, and it should provide its response via...
Jon Skeet
people
quotationmark

There's nothing you could do for this in a "normal" way, but there's one option you could consider... If you give your CreatureBehavior class just a private constructor, then nest PlayerBehavior and NonPlayerBehavior within that class,... more 7/16/2017 7:18:26 PM

people

C# equivalent of { }.Contains() in VB

I'm working on a VB = C# translator, and I've run across some VB code that I'm not sure has a direct translation to C#. In VB you can do something like If {"a", "b",...
Jon Skeet
people
quotationmark

If all the array elements will be the same type, or if they're different types but in a way that satifies type inference, you can use an implicitly typed array - like var but for arrays, basically: if (new[] { "a", "b", "b"... more 7/15/2017 7:53:48 AM

people

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