Browsing 7239 questions and answers with Jon Skeet

HTTP GET Server Incorrect Header

I am coding a HTTP Server, but when I create the header and send it. It returns: The connection to 127.0.0.1 was interrupted. My code to make the header is: string...
Jon Skeet
people
quotationmark

You're starting with a line break - you shouldn't. Basically, change this: string header = "\r\n"; header += "HTTP/1.1 200 OK\r\n"; to string header = "HTTP/1.1 200 OK\r\n"; more 6/6/2015 2:11:57 PM

people

Clone a file and modify it

I'm new to C# and I just want to use it for a project. I'd like to code a program that read some file and clone them line by line. If a line is a trigger, it would call a function...
Jon Skeet
people
quotationmark

The problem is that you're opening the output file on every iteration. Instead, you should have both files open at the same time: using (var reader = File.OpenText(@"c:\test.txt")) { using (var writer =... more 6/6/2015 1:13:06 PM

people

Java, date from string without pattern

I need to get a Date instance from input file. I don't know the date format, but I want to get it from user profile settings. Te following code does not working: DateFormat form...
Jon Skeet
people
quotationmark

I want to know if there is any way to get data from string without knowing the data string pattern. Without any more information, this is very error prone. For example, consider "7/6/2015" - does that mean June 7th, or July 6th? If... more 6/6/2015 12:52:07 PM

people

Input string was not in a correct format error, but still able to get parsed value from LINQ to XML query

I have an xml file from which I go get IDs from certain nodes. The nodes have the following structure: <Bistot ID="1223"/> <Compressed_Bistot...
Jon Skeet
people
quotationmark

The issue is that when you use ElementAt(0), it only needs to find the first element - so if there's an ID element later with an invalid value (which I'm sure there is), you're not going to hit it. When you call Count() or ToList(), it... more 6/5/2015 3:51:23 PM

people

Parameters not replacing properly in NpgsqlCommand

I'm trying to replace parameters in a string to execute in an Npgsql query. The problem is, when it replaces the parameter by its value in the string it adds unnecessary...
Jon Skeet
people
quotationmark

SQL parameters are generally only valid for values (e.g. the values of fields) - not field names and table names etc. While it's annoying, you'll probably need to embed these names directly into the SQL. You should be very careful doing... more 6/5/2015 3:46:44 PM

people

I'm only assigning one value to my final variable but still I'm getting an error

I'm getting an error when making my instance Strings cardRank and cardSuit final and I think that I'm only assigning them values once in my code. I've commented which ones I'm...
Jon Skeet
people
quotationmark

You can only assign to a final field within a constructor body (or as part of the declaration, or an instance initializer). So basically, you should ditch your setSuit and setRank methods. public Card(String cardRank, String cardSuit) { ... more 6/5/2015 2:12:23 PM

people

Creating a stream out of an httppostedfile always returns an empty file

I have the following code: file.InputStream.Seek(0,0); Stream s = file.InputStream s.Position = 0; s = File.Create(path); My goal is for the final output to be a duplicate of...
Jon Skeet
people
quotationmark

The problem is this line: s = File.Create(path) That doesn't do what you want it to. That's creating a new stream - at which point you're ignoring the old one entirely. You probably want something like: using (var output =... more 6/5/2015 2:09:49 PM

people

Why CLR do boxing when done casting from Structure to Object?

Every one know, when we takes Struct (Value Type) and pass to function, which wait for Object, boxing occurs. But, struct inherits from ValueType, which inherits from...
Jon Skeet
people
quotationmark

But p already is Object (if you do "p is Object" you will get true). That doesn't mean the value of p is already a reference. From the C# spec 7.10.10, the is operator - just the relevant part, where D is Point here, and T is... more 6/5/2015 1:03:02 PM

people

Linq query between dates

if ((!(searchStartDate == default(DateTime))) && (!(searchEndDate == default(DateTime)))) { requests = requests.Where(x => x.CreatedDate >= searchStartDate...
Jon Skeet
people
quotationmark

I strongly suspect the problem is that your start and end date values are the exact same point in time - so only values at that exact point in time will be found. For example, suppose you have: searchStartDate:... more 6/5/2015 8:42:35 AM

people

The string is getting the wrong value

I am trying to build a string like 11 11 but I am facing problem I am getting for start the following string 98 11 and not 11 11. How can I fix that? I appreciate any...
Jon Skeet
people
quotationmark

Yes, this is due to the associativity of +. This: String start= number+number+" "+number+number; is effectively: String start = (((number + number) + " ") + number) + number; So you're getting number + number (which is performing... more 6/5/2015 8:38:34 AM

people