Browsing 7239 questions and answers with Jon Skeet

PersianCalendar can't convert year/month/31(day) to standard date

I am trying to convert persianDate to standarddate . public DateTime ConvertPersianToEnglish(string persianDate) { string[] formats = { "yyyy/MM/dd", "yyyy/M/d", "yyyy/MM/d",...
Jon Skeet
people
quotationmark

Sergey's solution of explicitly using a culture which uses the Persian calendar should work, but another option is to use my Noda Time library: using System; using System.Globalization; using NodaTime; using NodaTime.Text; public class... more 8/28/2014 6:20:34 AM

people

C# breaking changes under the covers

Our prod and dev machines are running .Net 4.5 but our build servers are .Net 4.0. We are targeting .Net 4.0 and Im trying to assess the impact of building on a machine with 4.0....
Jon Skeet
people
quotationmark

I can replicate the problem for the lambda example. When I run the app on a 4.0 and 4.5 server it behaves the same. If you mean the change in behaviour in C# when it comes to capturing the iteration variable in a foreach loop, that is... more 8/28/2014 5:59:12 AM

people

Does accessing methods in a non static way affect/benefit performance?

Assuming all method calls here are static, like this: public class Util { public static void method1() { } } Accessing in a static...
Jon Skeet
people
quotationmark

Is there any performance difference for either way? Yes - the second is marginally slower, due to a pointless instance being constructed. I know the first way of doing it here is accessing it properly. But the second way only... more 8/27/2014 10:32:06 PM

people

Collection being modified during loop when there is no way it can be C#

The following code's foreach statement throws an InvalidOperationException saying "Collection has been modified. Enumeration operation cannot execute." I don't see how this is...
Jon Skeet
people
quotationmark

I don't see how this is possible, seeing as colors can never be modified after it's initialization. It's a view on the dictionary's keys... and you're modifying the dictionary here: colorDictionary[c]--; Admittedly that's not... more 8/27/2014 9:51:59 PM

people

How to remove milliseconds from LocalTime in java 8

Using the java.time framework, I want to print time in format hh:mm:ss, but LocalTime.now() gives the time in the format hh:mm:ss,nnn. I tried to use...
Jon Skeet
people
quotationmark

Just create the DateTimeFormatter explicitly: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss", Locale.US); LocalTime time = LocalTime.now(); String f = formatter.format(time); System.out.println(f); (I prefer to... more 8/27/2014 8:46:32 PM

people

Cannot get my base64 string to decode on my javascript client

I am sending data from my java tomcat server to my browser using a WebSocket. I get the error: "Uncaught InvalidCharacterError: 'atob' failed: The string to be decoded is not...
Jon Skeet
people
quotationmark

My base64 string looks like this on the java and javascript side: [B@74193bd0[B@24a6103c That's not base64. That's the concatenation of the result of calling toString() on two byte arrays. You're using a method which returns a byte[],... more 8/27/2014 7:58:55 PM

people

comparing two lists with LINQ

Let's say that I have these two lists of Persons. The Person object has FirstName, LastName, and Age properties. List A David Smith, 38 David Smith, 38 Susan Johnson, 23 List...
Jon Skeet
people
quotationmark

Once you've got a class which implements IEquatable<T> or IEqualityComparer<T>, it's easy to do the rest with Except and Any: if (collectionA.Except(collectionB).Any()) { // There are elements in A which aren't in... more 8/27/2014 7:56:00 PM

people

combining empty/null arrays

I have a page that can pass anywhere from 1 array to 3 arrays. My current code works but only if each array is populated with items. [HttpPost, ValidateInput(false)] ...
Jon Skeet
people
quotationmark

Well you're missing the fact that Concat will throw an exception if you pass it a null reference... but it's easy enough to fix. Either write an extension method like this: public static IEnumerable<T> NullToEmpty<T>(this... more 8/27/2014 7:48:47 PM

people

is there any date format for half year ad quarter year

Is there any format pattern I can use with SimpleDateFormat for quarter year and half year? 2007-01-23 expected output `Q1 2007` 2007-01-23 expected output `H1 2007`
Jon Skeet
people
quotationmark

No, there's nothing like that, as far as I'm aware. I wouldn't put it past different companies to have different ideas of "Q1" and "H1" to start with, to be honest - such as "Q1 ends at the end of the last week which starts in... more 8/27/2014 5:41:37 PM

people

An object inside its own class

So let's say: public class Sample { //main() class public static void main(String[] args) { A a = new A(); } } public class A { A aa = new A(); } So...when I...
Jon Skeet
people
quotationmark

Well, it's using both heap and stack. The stack space is because you're in the constructor for A, recursively. It would be simpler to see this if you put the initialization in the body of the constructor: public class A { A aa; ... more 8/27/2014 4:26:05 PM

people