Browsing 15485 questions and answers with Jon Skeet

Accessing GenericTypeParameters of generic type in C#

I want to generate the name of the generic class with their declared parameter names. For example if I have generic class and instantiated ones like shown below I want to print...
Jon Skeet
people
quotationmark

I think you're just looking for Type.GetGenericArguments, which you should call on genericType rather than type - at that point, the type "arguments" are really the type parameters because it's an open type. Sample (using... more 12/23/2016 9:42:24 PM

people

How to remove single and double quotes at both ends of a string

I would like to remove single or double quotes from both ends of a string. The string may contain additional quotes or/and double quotes which shall remain untouched - so...
Jon Skeet
people
quotationmark

Option 1: Removing all single and double quotes from start and end You can use replaceAll which accepts a regular expression - replace doesn't - and do it twice, once for quotes at the start of the string and once for quotes at the... more 12/23/2016 8:59:40 AM

people

C# '\n' saved in different bytes than expected

If I save this string to a text file; Hello this \n is a test message The \n character is saved as HEX [5C 6E] I would like to have it saved as [0A]. I believe this is an...
Jon Skeet
people
quotationmark

At execution time, your string contains a backslash character followed by an n. They're encoded exactly as they should be. If you actually want a linefeed character, you shouldn't be escaping the backslash in your code: Byte[] bytes = new... more 12/20/2016 10:32:36 AM

people

System.IO.FileNotFoundException, Newtonsoft.Json .Net

I have .NET console application and there is a problem with newtonsoft library. When I start console application with Visual studio by clicking start button, there is no problem....
Jon Skeet
people
quotationmark

Don't run it from the obj\Debug directory - the obj directory is basically temporary build artefacts. Instead, run it from the bin\Debug directory, where you'll find all the dependencies (in this case Newtonsoft.Json.dll) are present as... more 12/20/2016 9:54:03 AM

people

EventHandler<T> and EventHandler

I want to ask the different between EventHandler and EventHandler<T>. Previously I have implemented a EventHandler, with a custom EventArgs which can be passed to the...
Jon Skeet
people
quotationmark

EventHandler<T> is just a generic EventHandler type, which avoids you having to declare a new delegate type for each kind of EventArgs you want to use. Consider Control.KeyPress for example. It's declared as an event of type... more 12/20/2016 9:50:49 AM

people

What is the option in C# having capability of same like 'IN' in SQl

I want to search more than one Condition in an if Conditional block same like IN operator does in SQL. public class Check{ int [] arr={1,2,5,9,7,11,89}; for(int...
Jon Skeet
people
quotationmark

There's nothing in C# as a language that's equivalent to IN, no... but you can achieve a similar effect easily. The simplest approach is to probably to use System.Linq and Contains against an array: using System; using... more 12/18/2016 2:25:20 PM

people

SQLException: No suitable driver found for org.sqlite.JDBC

I am trying to run a code, which connect to SQLite database, using an Ant builder. When connecting I recieve a "java.sql.SQLException: No suitable driver found for...
Jon Skeet
people
quotationmark

You're passing an inappropriate value to DriverManager.getConnection. It's meant to be a JDBC URL - you're just passing in a class name. The JDBC URL for SQLite would be something like "jdbc:sqlite:/home/leo/work/mydatabase.db" more 12/17/2016 9:14:33 PM

people

Using nameof to access member of generic class without knowing the type

Take these two classes: class NonGenericClass { public string Member { get; set; } } class GenericClass<T> { public string Member { get; set; } } I can easily do...
Jon Skeet
people
quotationmark

No, there's no way of using nameof for a generic type (or a member of that generic type) without specifying a type argument. I would personally like to be able to specify the open type as you can with typeof, i.e. // Would be nice, but... more 12/17/2016 8:59:50 PM

people

Why am I receiving a NoClassDefFoundError when running a JAR file from CMD?

I have jar file placed under C:\temp inside jar Manifest file contains and all related jar files are there under lib folder Manifest-Version: 1.0 Ant-Version: Apache Ant...
Jon Skeet
people
quotationmark

You're assuming that the Class-Path refers to jar files within the jar file. It doesn't work that way. From "Adding classes to the JAR file's classpath": Note: The Class-Path header points to classes or JAR files on the local network,... more 12/16/2016 1:19:15 PM

people

Wait for page load before downloading with WebClient

I have several URLs stored in a text file, each of them is a link leading to a Facebook emoji, like https://www.facebook.com/images/emoji.php/v5/u75/1/16/1f618.png I'm trying to...
Jon Skeet
people
quotationmark

Nothing's being corrupted by your download - it's simply Facebook deciding (sometimes, which is odd) that it doesn't want to serve the image to your client. It looks like it's the lack of a user agent that causes the problem. All you need... more 12/16/2016 8:47:17 AM

people