Browsing 7239 questions and answers with Jon Skeet

How to add a second where clause to a linq expression

Trying to add a second where clause to a linq expression but it won't register. var query = _dbSetBookedResource.AsQueryable<Resource>(); var resources = (from Resource in...
Jon Skeet
people
quotationmark

For some reason the second where clause won't register. That's because you're not using the return value anywhere. That's just setting up a query, but then ignoring it. No LINQ methods change the value they're called on - instead they... more 6/25/2014 6:36:32 PM

people

why is folder created in server and not local PC

I have a ASP.net website and in the code behind I am creating a folder on page load, if it doesn't exist in the local drive: string strDirectory = @"C:\PDFGenerate\"; try ...
Jon Skeet
people
quotationmark

The issue I am experiencing is whenever I access the website from my local PC, the folder is being created in the server and not in my PC. Yes. That's because all your code is being executed on the server. The server just delivers... more 6/25/2014 5:34:11 PM

people

Android Date to C# long DateTime Ticks

I have an Android App and a C# mvc Web API. I want to sent a Date (and some other data) with a HttpPOST from the Android App to the WebAPI. Right now I use long ticks =...
Jon Skeet
people
quotationmark

Date in Java doesn't have ticks - it has milliseconds. Additionally, the epoch for Date is the Unix epoch (1970-01-01) whereas the epoch for DateTime is 0001-01-01. You need to take both of these into account - as well as the fact that the... more 6/25/2014 3:13:01 PM

people

Find the Non integer value from a List<T> using LINQ or Lambda C#

I have a class as : public class MyClass { public string Name{set;get;} public string Value {set;get;} public int ParentId {set;get;} } My Class Value property can have...
Jon Skeet
people
quotationmark

It sounds like you want something like: var nonInteger = list.Where(x => { int ignored; return !int.TryParse(x.Value, out ignored); ... more 6/25/2014 12:01:14 PM

people

Get last written files without time using LINQ

I have a folder with 198 files, among them there are 25 files with last writing date of 06.22.2014. I'm trying to get this set of last modified files, using the following...
Jon Skeet
people
quotationmark

It's easier to tell what you're doing if you don't just align on dots, but on top-level calls: public static IEnumerable<FileInfo> GetLatestFiles(string path) { return new DirectoryInfo(path) .GetFiles("*.log") ... more 6/25/2014 10:27:02 AM

people

How can I group odd and even using LINQ?

I'd like to use LINQ to group my odd and even numbers in two separate arrays. int[] randNum = randomNums(20, 1000, 1000); var oddEvnNums = from num in randNum ...
Jon Skeet
people
quotationmark

Just create a lookup with a key of num & 1 (equivalent to num % 2 for positive numbers, but sticking with 1 instead of -1 for negative numbers): var lookup = randNum.ToLookup(num => num & 1); var even =... more 6/25/2014 7:15:33 AM

people

Java: handle exception and return result from inner method

Question: How to do both: handle exception in outer method and return result of inner method? I have: two methods which return List: import java.util.List; import...
Jon Skeet
people
quotationmark

No - the inner method doesn't return anything, because it throws an exception instead. The outer method simply doesn't have a result to work with. If a method throws an exception, it's generally expected that none of the work in the... more 6/24/2014 5:47:05 PM

people

Why is dynamic not making the assumption that it can support this operation?

I have a class like this: public sealed class Repository<T> : IRepository<T> where T : RepositoryEntryBase, IRepositoryEntry, new() { /*Insert Stuff...
Jon Skeet
people
quotationmark

Consider non-dynamic code within Repository<T>. It could have: IRepositoryEntry entry = new T(); That's perfectly valid code - but isn't going to work with T=dynamic. You can perform any operation on a value of type dynamic, but... more 6/24/2014 5:31:07 PM

people

Might a Stream write less than the buffer size?

The intellisenses for Stream.Read and Stream.Write are very similar. Which leads me to the question of whether Write has the same gotcha as Read - It reads at most as many bytes...
Jon Skeet
people
quotationmark

No, Write will always write everything you ask it to. It may be buffered along the way, but you don't need to worry about "rewriting" in the same way as you repeatedly read data. more 6/24/2014 11:31:17 AM

people

Will Java's split override the length of array even if it is pre initialized?

String [] arr = {" "," "," "," "}; // String arr = new String[4]; String splitThis = "Hello, World, There"; arr = splitThis.split(","); arr[3] = "YAY"; The fourth line throws...
Jon Skeet
people
quotationmark

No, the array isn't length 4. The array is of length 3, because it's the result of the split operation. Your code is effectively just: String splitThis = "Hello, World, There"; String[] arr = splitThis.split(","); arr[3] = "YAY"; Once... more 6/24/2014 11:10:06 AM

people