Browsing 7239 questions and answers with Jon Skeet

LINQ to Entities does not recognize the method 'get_Day()' method

So I'm trying to create an Expression That does a DateTime Compare on the Day of a Paticular date specified through an expression. However I keep getting the Error LINQ to...
Jon Skeet
people
quotationmark

You probably want to use SqlFunctions.DatePart - that's basically the way of creating a query using DATEPART in the SQL. more 4/27/2015 5:54:27 PM

people

How to add an item only if no other items exist with the same name in the arraylist?

How would I go about only inserting an item if the item does not have the same name as the other items in the arraylist within my insertUniqueItem() method? public void...
Jon Skeet
people
quotationmark

I would probably use a LinkedHashMap<String, Item> instead, where the key is the name of the item. That way: You still get to preserve ordering You can easily and efficiently check whether there's already an entry for a given item... more 4/27/2015 5:35:25 PM

people

Storing event times, UTC issues when DST

I searched for this before asking but couldn't find anything that helps. I have a server that uses UTC, the clients can set the time of an event that the server executes daily...
Jon Skeet
people
quotationmark

If you want to represent a repeated event, you definitely need to store the local time and the time zone, and either store or decide on the policy for what to do if that time becomes invalid or ambiguous. (Suppose the user stores 02:30 -... more 4/27/2015 3:19:32 PM

people

IO Output different from expected

I have a .txt file that contains: 123456 45789 check check I want to replace check to now, I wrote the following code but the result was not as I...
Jon Skeet
people
quotationmark

The problem is that File.OpenWrite is reopening the same file for writing without truncating it first. You could use File.Create instead, or better yet use the methods which make reading and writing text simple: string path =... more 4/27/2015 1:40:56 PM

people

Java Socket waiting for UTF8

I am trying to implement a client-server application by myself. Its working so far, except the fact, that when I am accessing the port via another application (e.g. Web-Browser)...
Jon Skeet
people
quotationmark

You're calling DataInputStream.readUTF8. That expects data like this: First, two bytes are read and used to construct an unsigned 16-bit integer in exactly the manner of the readUnsignedShort method . This integer value is called the... more 4/27/2015 1:14:10 PM

people

.net collections optimization

I'm not really experienced in .Net Collections. Here I have the code I would like to rewrite somehow. emptyOrganization.Name = ""; var organizations = new...
Jon Skeet
people
quotationmark

(I'm assuming that emptyOrganization is an IOrganization and that GetAll returns an IEnumerable<IOrganization> or something similar...) Your code is already efficient, but you might want to try to make it clearer. You could... more 4/27/2015 12:35:50 PM

people

C# How to parse json data without key name?

I have json string like this: {"fields":[{"type":"none","options":["option1","option2","option3"]}]} I'm using JObject to parse json data. I can parse data that has name, like...
Jon Skeet
people
quotationmark

The value of options is just an array of values - like fields is. But each value in there is just a string, rather than a further map of key/value pairs. So you could use: string firstOption = (string)... more 4/27/2015 11:05:09 AM

people

java.text.ParseException: Unparseable date: "2014/02/20"

I ma getting exeception while parsing the date. following is the code: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD"); Date d =...
Jon Skeet
people
quotationmark

Not only have you got the slashes/dashes wrong, you're also using DD (day of year) instead of dd (day of month). You want: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); As always, read the documentation to find out... more 4/27/2015 10:44:25 AM

people

Get file that PrintWriter writes to

How do you get the name of the file that a PrintWriter object is writing to? PrintWriter myPrintWriter = new PrintWriter(fileName, "UTF-8"); I need the fileName parameter.
Jon Skeet
people
quotationmark

You can't - it might not even be writing to a file, e.g. StringWriter stringWriter = new StringWriter(); PrinterWriter printWriter = new PrintWriter(stringWriter); If you need this information, you could potentially create a subclass of... more 4/27/2015 10:09:14 AM

people

How do I remove blank lines from text File in c#.net

I want to remove blank lines from my file, foe that I am using code below. private void ReadFile(string Address) { var tempFileName = Path.GetTempFileName(); try { ...
Jon Skeet
people
quotationmark

The best solution may well depend on the disk type - SSDs and spinning rust behave differently. Your current approach has the advantage over Steve's answer of being able to do processing (such as encoding text data back as binary) while... more 4/27/2015 5:17:40 AM

people