Browsing 15528 questions and answers with Jon Skeet

Long running initialisation of class fields in constructor

Say I have the class below public class MyClass { private readonly NinjaObject _myNinja; MyClass(NinjaFactory ninjaFactory) { _myNinja =...
Jon Skeet
people
quotationmark

I presume you could create the Ninja asynchronously through some kind of static factory method, but then you run the risk (at least theoretically) of the Ninja not being ready (i.e. a null object) to attack when called to do so by the... more 3/26/2017 8:49:14 AM

people

Singleton Design Pattern Java

Does the class below implement the singleton pattern? I'm really confused. class Customer { static private Map costumers = new HashMap(); private Customer() { } ...
Jon Skeet
people
quotationmark

No, it doesn't. Thread-safety and type-safety issues aside, I can very easily get two different instances of Customer: Customer x = Customer.getInstance("first"); Customer y = Customer.getInstance("second"); System.out.println(x == y); //... more 3/26/2017 8:46:01 AM

people

Get weekofweekyear in NodaTime asp.net core

public static int IsoWeekOfYear(this DateTime dateTime) { var date = new LocalDate(dateTime.Year, dateTime.Month, dateTime.Day); //weekOfWeekYear ...
Jon Skeet
people
quotationmark

If you're using .NET Core, you're probably using a beta of 2.0. (I'm hoping to release 2.0 within a week.) The week-of-week-year handling has been overhauled for 2.0. In 2.0 you'd use: return... more 3/24/2017 2:56:23 PM

people

C# iterate through 2d array

I the following array: And I need to output the values as follows: "API Docs Portal : op-api-docs" "Big Ideas : op-bigideas" "Education : op-education" .... I've tried...
Jon Skeet
people
quotationmark

It's not clear why you've got two loops here. You always want the same two elements for each row - index 1 and index 2. So you just need: for (var x = 1; x <= reportValue.GetLength(0); x++) { var id = reportValue[x, 1]; var... more 3/24/2017 2:40:57 PM

people

Why do most serializers use a stream instead of a byte array?

I am currently working on a socket server and I was wondering Why do serializers like XmlSerializer BinaryFormatter Protobuf-net DataContractSerializer all require a...
Jon Skeet
people
quotationmark

It means you can stream to arbitrary destinations rather than just to memory. If you want to write something to a file, why would you want to create a complete copy in memory first? In some cases that could cause you to use a lot of extra... more 3/24/2017 1:26:52 PM

people

Google API .NET Core support?

we are recently looking at the feasibility of refactoring our BigQuery streaming process, which is a traditional .NET Windows console application, into .NET Core, so that it can...
Jon Skeet
people
quotationmark

In addition to Chris's answer, other things to note when using BigQuery from Container Engine: Assuming your cluster has been initialized with the right scopes, you should be able to use Application Default Credentials from Container... more 3/24/2017 7:30:10 AM

people

NuGet attempting to restore wrong version

I have a C# project with the following NuGet references: <packages> <package id="Pidac.HealthCare.Appointment.Model" version="1.0.0.0" targetFramework="net40"...
Jon Skeet
people
quotationmark

It sounds like you're seeing a breaking change in NuGet 3.4 A zero in the fourth part of the version number will be omitted 1.0.0.0 is treated as 1.0.0 1.0.01.0 is treated as 1.0.1 It's hard to know exactly what to suggest here,... more 3/23/2017 7:22:09 PM

people

Run code if a full year has elasped

I want to send an email to a user every year based on the date on which their account was created. I currently have code for checking if a number of months have passed since they...
Jon Skeet
people
quotationmark

It seems to me that the right approach is to change your design - instead of asking for the months between one date and another, you should add the relevant number of months to your original DateTime. You don't need a helper method for... more 3/23/2017 11:36:37 AM

people

Json Deserialised don't override the default values in the property

public class Student { public string Name { get; set;} = "ABCD"; public List<Subject> Subjects {get; set;} public Student() { Subjects...
Jon Skeet
people
quotationmark

Well, your expectations are incorrect. Basically, the JSON deserializer is - entirely reasonably, IMO - executing code equivalent to: var student = new Student { Name = "ABC", Subjects = { // Each line here will just... more 3/22/2017 2:28:46 PM

people

Download Google.Protobuf/3.1.0 nuget packages to local machine using powershell

I have got this below script in below blog which will Download all nuget packages to my local server using power-shell script. I have used same script to download...
Jon Skeet
people
quotationmark

https://www.nuget.org/packages/Google.Protobuf/3.1.0/ isn't a feed URL base - that's a page for a specific package. It looks to me like this: $serviceBase = GetPackageUrl($feedUrlBase) $feedUrl = $serviceBase + "Packages" can just be... more 3/22/2017 1:35:43 PM

people