Browsing 7239 questions and answers with Jon Skeet

The type T must be a reference type in order to use it as parameter while using interface

I got the error for the below code public static Moq.Mock<T> CreateInstanceOfIMock<T>() { return new Moq.Mock<T>(); } I have solved the error it by using...
Jon Skeet
people
quotationmark

There's no generic constraint in C# to enforce that a type argument is an interface. But where T : class is really "where T is a reference type" - it includes interfaces. If you wanted to enforce that T is an interface rather than a... more 11/30/2017 7:04:57 AM

people

why folder structure is not created even though I had taken package statement?

I was trying a package concept in java. I created a Test.java file that only contains a single statement: package pack1; When I compile the file using the command as: javac...
Jon Skeet
people
quotationmark

In your original code, you haven't declared any classes - so there wouldn't be any class files. If there are no class files, presumably the compiler sees no need to create the directory structure that would have been necessary for any... more 11/29/2017 11:17:24 AM

people

Why is this class not considered a supertype as a parameter?

Given the following example, why am I able to override the return type List<? extends IConfigUser> as List<ConfigUser> in getUserList() but cannot do the same for the...
Jon Skeet
people
quotationmark

You can return a more specific type in an override, but you can't require that you accept a more specific type. Get rid of the generics, and you can override a method returning Object with a method returning String, but you can't override... more 11/29/2017 11:09:57 AM

people

C# TimeZoneInfo to convert GMT timezone name to system timezone

In windows, we get timezone list like this: ID Time zone name Display string -- -------------- -------------- 0 Dateline Standard Time ...
Jon Skeet
people
quotationmark

If you're happy to stick with TimeZoneInfo and DateTime/DateTimeOffset, you can use Matt Johnson's TimeZoneConverter library to convert the IANA ID (the part in brackets, e.g. Pacific/Kiritimati) to a Windows system time zone ID. Examples... more 11/29/2017 9:51:08 AM

people

Async/await performance

I'm working on performance optimization of the program which widely uses async/await feature. Generally speaking it downloads thousands of json documents through HTTP in parallel,...
Jon Skeet
people
quotationmark

Task.Delay isn't broken, but you're performing 100,000 tasks which each take some time. It's the call to Console.WriteLine that is causing the problem in this particular case. Each call is cheap, but they're accessing a shared resource, so... more 11/26/2017 12:25:37 PM

people

Java variable declaration not allowed

I've made 2 pieces of code. The first works fine, but the other says the variable declaration not allowed here. First code(Working) class Test { public static void...
Jon Skeet
people
quotationmark

What the reason behind it i think both the codes are nearly same. Nearly, but not quite. To understand why the compiler is complaining, it's often a good idea to look at the language specification. The body of a ForStatement has to... more 11/25/2017 10:45:46 AM

people

Update nuget package referenced by package

I have a nuget-package A in my project that uses nuget-package B. When I update package B I alway have to update the nuget-package-rerefence to B in nuget-package A and then...
Jon Skeet
people
quotationmark

Is there any way to directly update the implicitly referenced nuget-package B in my top-level-project? Sure, just add a direct dependency from your project to package B - then you can specify the version you want. When package A is... more 11/23/2017 4:09:17 PM

people

Java SimpleDateFormat does not parse correctly (I am using the correct uppercase/lowercase letters..)

I know this has been asked several times and I am risking a downvote/duplicate close, but most of the questions posted here were resolved by chaing YYYY into yyyy..so, searching...
Jon Skeet
people
quotationmark

How is that possible? The new block was created before the old block, as seen in the timestamp. but now it is the other way around S in a SimpleDateFormat format string always represents milliseconds - not just "fractions of a second"... more 11/23/2017 11:12:16 AM

people

read file using InputStreamReader?

Basically I have a web-app and I am trying to read youtube API client_secrets.json using InputStreamReader and assign its value to Reader. I tried: Reader clientSecretReader =...
Jon Skeet
people
quotationmark

You're trying to load a file, but you're using Class.getResourceAsStream to do so. If you want to load a file, use a FileInputStream. If you want to load a resource which is accessible to a ClassLoader, use Class.getResourceAsStream or... more 11/22/2017 8:46:51 AM

people

Unicode.GetString in C#

I encountered a strange issue when doing some byte array stuffs together with unicode string in C#. Below is my code. var bytes = new byte[] {128, 216}; var strstr =...
Jon Skeet
people
quotationmark

From my opinion, GetString and GetBytes should be opposite operations. They are, when the data represents a valid string. However, you've tried to decode 0x80 0xD8 as a little-endian UTF-16 string - but that's not a binary... more 11/22/2017 6:27:48 AM

people