Browsing 7239 questions and answers with Jon Skeet

Doubled Decimal Point in Emails on New Line

When I send an HTML email (actually just generating .eml files rather than sending at the moment) using the .NET System.Net.Mail.MailMessage class, it seems to be adding addition...
Jon Skeet
people
quotationmark

I suspect you're just running into the fact that a period at the start of a line is used to terminate a mail. From RFC 2821 section 4.5.2: 4.5.2 Transparency Without some provision for data transparency, the character sequence ... more 4/9/2014 10:17:34 AM

people

Speed up byte parsing possible?

We are doing some performance optimizations in our project and with the profiler I came upon the following method: private int CalculateAdcValues(byte lowIndex) { byte...
Jon Skeet
people
quotationmark

I strongly suspect that after casting to byte, your indexes are being converted back to int anyway for use in the array indexing operation. That will be cheap, but may not be entirely free. So get rid of the casts, unless you were using... more 4/9/2014 9:38:48 AM

people

Dictionary getting top most elements

Friends I have created a dictionary. For getting top 2 elements I am using below code. topKeys[B] = (from entry in differentKeys orderby entry.Value descending ...
Jon Skeet
people
quotationmark

It's not clear why you keep converting to dictionaries all the time. The order of entries Dictionary<,> is not guaranteed. It looks like you just want: var topValues = differentKeys.Values ... more 4/9/2014 9:00:49 AM

people

Why concatenating strings in multiple lines faster than Adding String In One Statement?

Why the speed rank is: AddStringInMutipleStatement AddStringInOneStatement AddStringInMutipleStatementEx ? Is it related the temp string object created on runtime? What the...
Jon Skeet
people
quotationmark

Firstly, a few points on your benchmarking: I would suggest adding a call to each method before the timing starts, so that you're not measuring JIT compilation time I would suggest adding a call to GC.Collect() after each test, so that... more 4/9/2014 7:55:33 AM

people

Linq to sql datetime issue

When I am calling GetClosestStartDate it is popingup the following message Additional information: LINQ to Entities does not recognize the method 'System.String ToString()'...
Jon Skeet
people
quotationmark

The simplest approach is to fetch just the data you want in the part that's translated into SQL, and then do the rest locally: public List<Class_CourseStartdate> GetClosestStartDate(DateTime coeStartdate) { return... more 4/9/2014 7:28:49 AM

people

In C# dynamic key word performance?

If use dynamic Key Word & we assign some Type on it, is Compiler perform boxing/un-boxing Operation? For Example; dynamic myInstance=null; object...
Jon Skeet
people
quotationmark

Unless it's a value type, there'll be no boxing going on - but in the code sample you've used, there's no real use of dynamic typing anyway. Your code thus far is equivalent to: object key = "BankProject.Payment"; Type myType =... more 4/9/2014 7:20:00 AM

people

How do I round a C# datetime to datetime2(0)

In my integration tests I am trying to compare a C# DateTime that was inserted into a column that is defined as datetime2(0) so obviously it loses precision on the way back out...
Jon Skeet
people
quotationmark

Edited to perform rounding... So: long tickOfSecond = original.Ticks % TimeSpan.TicksPerSecond; long ticksToAdd = tickOfSecond < TimeSpan.TicksPerSecond / 2 ? -tickOfSecond : 10000000 - tickOfSecond DateTime truncated =... more 4/8/2014 9:48:51 PM

people

Finding day of the year

I'm trying to find the day of the year after you enter a date. I have a way that works but it is not the best way it seems. I ask for the date using a Scanner object then send it...
Jon Skeet
people
quotationmark

Depending on what you're using: Standard Java libraries, before Java 8 Calendar calendar = new GregorianCalendar(); // Just to avoid corner cases calendar.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); calendar.set(year, month - 1,... more 4/8/2014 9:38:50 PM

people

Calling C# executable from perl script

I am trying to execute a C# 4.0 console application from a perl script and trying to capture the output of the application. The C# application is a multithreaded application but...
Jon Skeet
people
quotationmark

The problem is that your application is trying to use the console in a relatively advanced way - setting the cursor position. In this case, you don't really have a console, you just have piped output... so there's no console handle, and... more 4/8/2014 9:35:48 PM

people

Getting xml from url not working

public class GetXMLTask extends AsyncTask<String, Void, String> { // XML node names static final String NODE_EVEN = "event"; static final String NODE_NAME = "name"; static...
Jon Skeet
people
quotationmark

Nothing is going wrong. You are successfully parsing an XML document, which you've got a reference to in the doc variable. All that's wrong is your expectation that Document.toString() will give you back something meaningful. It looks... more 4/8/2014 8:41:26 PM

people