Browsing 15528 questions and answers with Jon Skeet

DateTime Formatting on Azure hosted site

so my tech stack is: asp.net core 1.1 hosted on Azure using CSV Helper to read CSVs into a SQL database (in azure). ok so the problem i'm facing is when i'm using CSV helper...
Jon Skeet
people
quotationmark

If you want to make sure CsvHelper always uses one particular culture, you can set it explicitly: csv.Configuration.CultureInfo = auCulture; You should bear in mind, however, that a DateTime doesn't "store" a format - so once you've... more 2/9/2017 2:47:34 PM

people

How to find the most specific types in an arbitrary hierarchy

Let's say we have a collection of types: var types = new[] { typeof(IEnumerable<int>), typeof(ICollection<int>), typeof(Stack<int>), ...
Jon Skeet
people
quotationmark

It seems to me that Type.IsAssignableFrom is your friend here. You want types that aren't assignable from any of the other types in the set: using System; using System.Collections.Generic; using System.Linq; class Program { static... more 2/9/2017 12:17:47 PM

people

loading inner class without loading the enclosing class

I was bit confused when is the inner class (non static) gets loaded by the jvm . Is it dependent on the outer class. or can it be separately loaded without loading the outer...
Jon Skeet
people
quotationmark

Given that an inner class has a field with reference to an instance of the enclosing class, I don't see how it could be loaded without loading the enclosing class. A static nested class may well be different, as that's genuinely... more 2/8/2017 12:01:47 PM

people

Conversion of var to class type in C#?

I am new to C# and was going through ArrayList. My question is can we store different datatype - different classes, different structures into ArrayList and access them. I could...
Jon Skeet
people
quotationmark

Firstly, I'd advise you to not use ArrayList. Use List<T> where you can, although storing different types of objects in a list is a bit of an anti-pattern to start with. Convert.ChangeType doesn't do anything for you, and you should... more 2/8/2017 7:25:33 AM

people

Check if Set of Object contain an Object with this attribute

Consider i have a List Of Objects, and i convert it to a Set to make some actions like this : List<User> listUser = new ArrayList<>(); listUser.add(new User(1,...
Jon Skeet
people
quotationmark

Does your User class override equalsusing just the ID? If so, you could use: if (mySet.contains(new User(1, "irrelevant")); Note that it's quite odd to have something called mySet which is actually a List rather than a Set... I'd... more 2/7/2017 9:40:38 AM

people

C# Setting XML Node values as Stings from StreamReader result

I'm using an API call to return some XML data from a web server. The XML data is in the following format: <forismatic> <quote> <quoteText>The time...
Jon Skeet
people
quotationmark

You're trying to use doc.Element("quote") - there's no such element, so that's returning null. You'd want doc.Root.Element("quote"). Next you're asking for quoteText and quoteAuthor as if they were attributes - they're not, they're... more 2/3/2017 11:37:30 AM

people

Java 8 check statement for every list item

I have a const experience value, person object, list of skill and method (can not modify it) hasSkill(skill,person,experience). I want to check (method should return boolean) that...
Jon Skeet
people
quotationmark

It sounds like you want allMatch: return skillList.stream().allMatch(s -> hasSingleSkill(s, person)); As another more general matter, any time you have condition ? true : false you can just replace that with condition So your... more 2/3/2017 9:39:39 AM

people

SimpleDateFormat parsing results are odd

I want to parse dates from a filesystem and get them in this format: 2013-07-29 14:49:53.813588954 +0200 Therefore my pattern looks like this yyyy-MM-dd HH:mm:ss.SSSSSSSSS...
Jon Skeet
people
quotationmark

You've parsed 813588954 as a number of milliseconds - that's over 9 days, and it's being added to 2013-07-29 14:49:53. Basically, SimpleDateFormat doesn't handle parsing nanoseconds, and java.util.Date only supports millisecond precision... more 2/2/2017 10:10:02 AM

people

The blank final field INSTANCE may not have been initialized

I follow this post to create a thread safe singleton classs, but there is an compile error in INSTANCE. It said The blank final field INSTANCE may not have been initialized. My...
Jon Skeet
people
quotationmark

Given what you've said, you shouldn't be using class initialization for this. In particular: You want to try multiple times You want to use a checked exception Both of those are feasible, but you'll need to move the initialization into... more 2/1/2017 9:25:10 AM

people

What is the actual difference between assertEquals() vs assertTrue() in TestNG?

I'm confusing about both these methods, because both can do the same thing, like below snippet of my code. Using assertEquals() method: String a = "Hello"; String b =...
Jon Skeet
people
quotationmark

assertEquals is better because it gives the unit test framework more information about what you're actually interested in. That allows it to provide better error information when the test fails. Suppose you had String a = "Hello"; String... more 2/1/2017 7:33:39 AM

people