Browsing 7239 questions and answers with Jon Skeet

Type generated from string class name not recognized in newing of the same type

I have some vb.net code that takes a string version of a class name, finds the type in the assemblies and uses that type to create an instance of a generic list of that type using...
Jon Skeet
people
quotationmark

The problem is that you're treating the token Ty as if it were the name of a type. It's not - it's the name of a variable. The type of that variable is Type, but it's still a variable. Variables and type names are entirely different... more 4/1/2016 6:14:07 AM

people

How can I parse "1:15 P.M." into a NodaTime LocalTime?

Parsing "1:15 pm" is easy: var pattern = LocalTimePattern.CreateWithInvariantCulture("h:mm tt"); var time = pattern.Parse("1:15 pm").Value; However, this doesn't work with the...
Jon Skeet
people
quotationmark

Firstly, the "1:15 PM" version should work already - it does for me. If you want to allow "P.M" or "p.m". you'll need to create a culture with appropriate AM/PM signifiers. That's easy enough to do: using System; using... more 3/31/2016 8:20:03 PM

people

What is the order of Print Out about NEW Keyword in Inheritance?

It's actually part of one interview question I got confused. class A { public A() { System.out.println("A") ; } } class B extends A { public B() ...
Jon Skeet
people
quotationmark

why is A print before B? Because the body of the superclass constructor is executed before the body of the subclass constructor, basically. Think of your B() constructor as implicitly: public B() { super(); // This invokes A's... more 3/31/2016 7:36:07 PM

people

How to simulate method overloading based on generic return type in c#

I have a read model as IQueryable<CustomType>, I use this inside my Web application. A lot of time I need to extract from this read model different View Model. I use to...
Jon Skeet
people
quotationmark

One option is to have a map from the type to a conversion of CustomType to that type. So it would look something like: private static readonly Dictionary<Type, Expression> Mappings = new Dictionary<Type, Expression> ... more 3/31/2016 3:38:23 PM

people

How to base 64 encode a hex string

I am trying to base-64 encode a hex string (copied below) but the values that I get from the Java8 call to encode to base64 do not match what I am getting on different online...
Jon Skeet
people
quotationmark

This doesn't do what you expect it to: hexString.getBytes(StandardCharsets.UTF_8) That's just encoding the hex string as UTF-8 - you want to parse the hex string, so that each pair of hex digits ends up as a single byte. The fact that... more 3/30/2016 9:01:25 PM

people

Join with Where Clause in LINQ

I've got two tables that I'm trying to join together with an ID, but only select rows from Table A, where a value in Table B is null. I tried this: var dbXMLSoccerTeams = (from...
Jon Skeet
people
quotationmark

It seems to me that you should actually use a join: var dbXMLSoccerTeams = from dbXMLSoccerTeam in data.EFXMLSoccerTeam join dbMatchTeam in data.EFMatchingTeamIDs on dbXMLSoccerTeam.ID... more 3/30/2016 6:02:26 PM

people

bufferedReader closing a File

I get this error when I trying the get kincaid value of a java file. I couldn't find what i should do.As I understand it's a problem about closing a file. I have tried another...
Jon Skeet
people
quotationmark

You're calling three methods, providing the same InputStream to all of them - and each of them creates a BufferedReader wrapping that InputStream, and then closes it at the end. Closing the BufferedReader will close the underlying... more 3/30/2016 5:56:48 PM

people

C# parse from string to Keys

Currently I have to parse from string to Keys somehow. So basically as input I get something like "Keys.Shift" and somehow I need be able to parse this to keys so I can use it...
Jon Skeet
people
quotationmark

It sounds like you've got another class called Keys somewhere. Here's an example demonstrating the same problem (although there's a second error around the declaration of key which you haven't mentioned; I suspect you've got that error as... more 3/30/2016 6:21:57 AM

people

Delegate isn't working

I come across a change in a program which my current infastructure couldn't handle and was become too long: I had to stop using such absolute code and move towards Object...
Jon Skeet
people
quotationmark

Is there a way that logos can be seen within the IntergrateLogo method by using a delegate? Not when it's a local variable, no. It's not really clear why you'd use delegates for this at all though. I wouldn't even use a method, but... more 3/29/2016 10:35:16 AM

people

access only parent node attribute without having children

I have an XML file and want to extract some nodes of it in a new XML file and save it. The XML file is as follows: <?xml version="1.0" encoding="utf-8"?> <files...
Jon Skeet
people
quotationmark

The simplest approach would just be to replace the child nodes of the root element instead: var root = XElement.Load(xmlFile); root.ReplaceNodes(new XElement("tests", root.Elements("test"))); root.Save(FileName + ".xml"); Note that... more 3/29/2016 9:44:04 AM

people