Browsing 7239 questions and answers with Jon Skeet

How to use IFormatProvider in DateTime.ParseExact

Why should we use IFormatProvider in DateTime.ParseExact if there is already a format parameter? DateTime.ParseExact(inputString, format, cultureInfo);
Jon Skeet
people
quotationmark

The format parameter says what pattern to use - but it doesn't say anything about which calendar, month names, short date format etc to use. That's up to the IFormatProvider. For example, suppose you wanted to parse a value with the... more 11/29/2013 1:44:36 PM

people

SQL query error :Incorrect Syntax Near "#"?

When I try to execute this SQL query: savInto.CommandText = "update onCommands set warnDate =#" & movDate.Value.ToString("MM/dd/yyyy") & "#,updateDate =#" &...
Jon Skeet
people
quotationmark

Well the main problem is that you're trying to provide the parameter as part of the SQL itself. While there are ways of doing that (use an apostrophe rather than #), it's generally a bad idea: It invites SQL injection attacks when used... more 11/29/2013 1:36:59 PM

people

Is this pattern for handling IO exceptions in Java correct?

In the following code snippet, if ex1 is thrown, will be be caught by the second catch block, or will it be thrown back to the caller of the method? And if it is thrown back to...
Jon Skeet
people
quotationmark

Both of those exceptions would be thrown back to the caller... although a single exception in any particular situation. If the body of the outer try block throws and then close throws as well, only the second exception would be seen by the... more 11/29/2013 11:45:37 AM

people

IOS cannot find true format to parse date

I have a problem on parsing a date in IOS. Here is the date I got: 2013-12-22T20:30:58.020Z and I cannot parse this date with the following code block: NSDateFormatter...
Jon Skeet
people
quotationmark

You're using hh, which is the 12-hour clock - but you've provided a value of 20. You want HH, which is the 24-hour clock: [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"]; more 11/29/2013 11:02:13 AM

people

DateTime.Date does not work in HTML5

I want do have my DateTime get displayed without the time. So I use item.AD_Date.Date to cut off the time. In the Model ( I use MVC) AD_Date is set up like this: public...
Jon Skeet
people
quotationmark

The Date property just returns a DateTime with the same date, but at midnight. There's no difference between "a DateTime at midnight" and "a DateTime just representing a date" (unfortunately). You need to change how your DateTime is... more 11/29/2013 10:31:01 AM

people

Where can I find the nameSpace System.Net.Mail (or similar) in .Net 3.5?

I need to program a functionality in .Net for sending mails. After some reading, I found that the classes from System.Net.Mail may be useful. Yet... I can't find that namespace...
Jon Skeet
people
quotationmark

If you've got a reference to System.dll, it should be fine - although looking at the documentation for some classes it looks like for the client profile of .NET 3.5, it was only introduced in .NET 3.5 SP1. So you either need the full... more 11/29/2013 8:29:45 AM

people

Interface implementation and common function

I have the following requirement, There will be 2(or more) different classes to perform same kind of operation(in different ways). Therefore I decided to create an interface....
Jon Skeet
people
quotationmark

It sounds like you want an abstract class implementing the common functionality, but still have two concrete classes for the distinct functionality. You may or may not still want to keep the interface as well. So the options are: ... more 11/29/2013 6:48:53 AM

people

C# GetRequestStream() outlook add in "The operation has timed out"

Good day. I really need help on this issue. I have tried every possible option here. I use a REST API in an Outlook add-in using C#. The code links outlook items to CRM records,...
Jon Skeet
people
quotationmark

I suspect the problem is that you're not disposing of the WebResponse. That means the connection pool thinks that the connection is still in use, and will wait for the response to be disposed before reusing it for another request. The... more 11/29/2013 6:44:57 AM

people

java replacing back strokes with other characters

I have come across this little problem. String fileAdress = "c:\red\"; System.out.println("Peach " + fileAdress); fileAdress = fileAdress.replaceAll("\", "\\\\"); ...
Jon Skeet
people
quotationmark

Use replace instead of replaceAll - replaceAll takes a regular expression as the first argument, which isn't what you want. This should be fine: fileAddress = fileAddress.replace("\\", "\\\\"); (I wish replaceAll had been called... more 11/28/2013 8:59:18 PM

people

Java order of expression evaluation with AND and OR

boolean a = false; boolean b = false; boolean c = false; boolean bool = (a = true) || (b = true) && (c = true); System.out.println("" + a + b +...
Jon Skeet
people
quotationmark

I believe the crux of your question is this part: But, the && operator has higher precedence than the || operator and should be evaluated first No. Precedence doesn't affect execution ordering. It's effectively bracketing. So... more 11/28/2013 5:54:33 PM

people