Browsing 7239 questions and answers with Jon Skeet

linq query and select statement

I have following linq var data = repository.FindAll().Where(x => x.Country.ID == ID).ToList(); var serializedData = (from c in data select new { ID = c.ID, Name = c.Name...
Jon Skeet
people
quotationmark

Well you should almost certainly get rid of the ToList() call, to start with - that way the selection part will be turned into SQL and avoid pulling down unnecessary data. You can do the whole thing in a query expression: var... more 6/2/2014 6:13:27 PM

people

Use IEnumerable<Expression<Func<T, Object>>> in method

I have the following method: public void Update<T>(T entity, IEnumerable<Expression<Func<T, Object>>> properties) where T : class { ...
Jon Skeet
people
quotationmark

It looks like you really want: public void Update<T>(T entity, params Expression<Func<T, Object>>[] properties) where T : class and then call it as: _repository.Update(file, x => x.Data, x =>... more 6/2/2014 4:41:50 PM

people

Euro symbol in GBK encoded Chinese language page

i have a page that is rendering words in Chinese characters. I am using the GBK encoding, and i am able to display and save Chinese characters successfully on my html page. User...
Jon Skeet
people
quotationmark

Apparently there is no Euro symbol in GBK. For example, from the code page 936 wikipedia page: The concept "CP936", "GBK" and "GB2312" are sometimes confused in various software products. Code page 936 is not identical to GBK because a... more 6/2/2014 4:08:36 PM

people

Different date format in Rest WS response in java

I have two SOAP and Rest webservices both has a field called CreatedDate. I am getting date from the DB and setting to the Date field of Java class. There are two different Output...
Jon Skeet
people
quotationmark

But format is different. Not really. They're both using the date/time format in RFC 3339 / ISO-8601, as per the W3C XML schema recommendation, which expresses an offset from UTC as well as the local date/time. Z is used as a UTC... more 6/2/2014 3:11:34 PM

people

Visual Studio clears output file at end of debugging

I am experiencing a weird behaviour from Visual Studio 2013. I've got a C# program which writes to the standard output, let's say using System; using System.Threading; namespace...
Jon Skeet
people
quotationmark

I believe this is due to the way Visual Studio hosts your application, in order to reduce startup time when debugging. What happens is that your application (Program.exe) will actually be hosted in another process (Program.vshost.exe),... more 6/2/2014 2:57:25 PM

people

Guice inject null check?

I am using google guice inject at the constructor level. Does it make sense to do a null check on the parameters to ensure they are not null or inject does that for us. Btw, its a...
Jon Skeet
people
quotationmark

Just because you happen to be using Guice to call the constructor in some cases doesn't mean anything else is prohibited from calling it. Personally, I would include the nullity checks - which are very light on cruft if you're using Guava... more 6/2/2014 2:48:36 PM

people

Cannot work with XML file. InputStream is null

What am I doing wrong here? I am getting the error there there is nothing in the input stream when that is not the case. The file is there and it is titled correctly. I want to...
Jon Skeet
people
quotationmark

This has nothing to do with XML. You're using Class.getResourceAsStream, which is meant to get a resource to be loaded from the classpath for that class's class loader... but you're passing in a filename instead. If you want to create an... more 6/2/2014 2:35:30 PM

people

How to encrypt a guid into equal length string in C#?

I need to encrypt a guid and the encrypted string length should be 32 char max, not more than that. Please suggest me an encryption method available in C# for that. I was using...
Jon Skeet
people
quotationmark

Well, a GUID is inherently 16 bytes of data... so that's what you should encrypt. That's a single block in AES. As per Reid's comment, the exact size of the output will depend on how you've configured things, but to convert the result into... more 6/2/2014 2:15:26 PM

people

Difference between Java and Javascript on 1st Jan 0001 UTC

I have a difference of how the date 1st Jan 0001 UTC is represented in Java and in Javascript In Java: TimeZone utcTimeZone = TimeZone.getTimeZone("UTC"); Calendar cal =...
Jon Skeet
people
quotationmark

It looks like this is because GregorianCalendar in Java is actually a hybrid between the Gregorian calendar and the Julian calendar: GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems... more 6/2/2014 2:06:02 PM

people

StackOverflowError in Java while working with arrays and recursion

The lifeCycle-method in my MatrixCreatureContainer-class throws a stack overflow error after about 3-4k iterations. Why is that? I assume it has something to do with memory...
Jon Skeet
people
quotationmark

With this call: lifeCycle(population,0, 4000); you're basically asking for a stack with 4000 frames (at least - see later). That isn't totally beyond reason, but in fact there's no reason to make this recursive at all. You can easily... more 6/2/2014 1:48:28 PM

people