Browsing 7239 questions and answers with Jon Skeet

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

How to loop all XML attributes without knowing the element

How do i loop all xml attribute without knowing the element name here is my sample xml <dd l="11243" t="641" r="11653" b="1004"> <para l="11276" t="768" r="11620"...
Jon Skeet
people
quotationmark

Just omit the "para" argument from Descendants() - that will obtain all the descendant elements. You can then call Attributes() (which in this case is an extension method on IEnumerable<XElement>) to obtain all the attributes from... more 12/16/2016 7:05:59 AM

people

c# access modifier section like c++

Do I need to write all access modifiers in c#? static class Node { Node link;//Node * link; int data; public: void setlink(Node next){...} void...
Jon Skeet
people
quotationmark

Yes, you specify it on each member. Two good things about this: Moving the methods around within the same class can't affect anything. You can immediately see the access modifier by looking at the method declaration. No need to look... more 12/15/2016 4:55:36 PM

people