Browsing 7239 questions and answers with Jon Skeet

Possible to ignore the Expression if it's null or empty without checking for null in an IF statement?

Well, I have two expression X , Y if flag is true then y has a expression I need a List<mylist> v = list.where(x).where(y).ToList(); In this case if the y expression...
Jon Skeet
people
quotationmark

You can add your own extension methods easily enough. It's not immediately clear whether you're using IQueryable<> or IEnumerable<> (your code wouldn't compile either way, due to casing issues and the fact that no Where method... more 11/16/2013 8:34:52 AM

people

Sending gzipped data over a network from C# to Java

I have an application that sends data gathered from a data source on my PC (say, Excel or Access) to a receiving app on an Android tablet. I am in the testing stage of compressing...
Jon Skeet
people
quotationmark

Because the data is read in by a BufferedReader, I have to convert from char[] to byte[] initially: That's a huge problem. You've compressed the data. It's arbitrary binary data. You should absolutely not be treating it as text. It's... more 11/15/2013 10:32:05 PM

people

I do not understand this code from MSDN

The following code is from this MSDN article a link, what I do not understand is in the Appendix B, all the way down in the article. private IEnumerator<ITask>...
Jon Skeet
people
quotationmark

Why does the code have two return states, It has two yield statements, Will both work? Yes. yield return will yield the given value to the method which is asking for the "next" value... but when the next value is asked for again, the... more 11/15/2013 10:20:47 PM

people

Singletons, Generic & Inheritance have all child classes inherit the singleton functionality

I've got two problems. One is that I'm trying to have an abstract singleton class, that has the singleton functionality + a little extra functionality in it, but this class is...
Jon Skeet
people
quotationmark

I suggest you introduce an attribute which you decorate each type with, and extract that when you need to. You won't be able to validate at compile-time that the type has the right type, but there's not a lot you can do about that. Unit... more 11/15/2013 10:07:54 PM

people

String not populating properly

I am writing a program that is going to read a string from a file, and then remove anything that isn't 1-9 or A-Z or a-z. The A-Z values need to become lowercase. Everything seems...
Jon Skeet
people
quotationmark

You're incrementing i in the each of the blocks as well as in the main loop "header". Indeed, because you've got one i++; in an else statement for the last if statement, you're sometimes incrementing i twice during the loop. Just get rid... more 11/15/2013 7:34:59 PM

people

Modifying each item of a List in java

I'm just starting to work with lists in java. I'm wondering what the recommended method to modify each element of a list would be? I've been able to get it done with both the...
Jon Skeet
people
quotationmark

EDIT: If you know that size(), get(index) and set(index, value) are all constant time operations for the operations you're using (e.g. for ArrayList), I would personally just skip the iterators in this case: for (int i = 0; i <... more 11/15/2013 11:53:33 AM

people

No value specified for parameter X. How to avoid?

I have an Insert query that puts some data into several columns: INSERT INTO table (a,b,c,d,e,f) VALUES (?,?,?,?,?,?); I have a script that parses some documents and based on...
Jon Skeet
people
quotationmark

Just set all the parameters to suitable default values. Then overwrite them with the "real" values as you find them in your input. Note that if some of your columns are primary keys, you can't usefully use default values for those -... more 11/14/2013 9:51:41 PM

people

How to filter Xdocument and return Xdocument?

My application gets data from SharePoint web service (using SOAP and CAML query), I am using a Xdocument doc to store retrieved xmlNode and then assign xdocument to XMLDataSource...
Jon Skeet
people
quotationmark

If you're just trying to create a document with those elements, you can use: XDocument filteredDocument = new XDocument(new XElement("root", bar)); (That will create a document with a root element of <root>, and all the elements... more 11/14/2013 6:35:58 PM

people

Having an issue passing by reference / value

I've got this method that is passed an array of files. It then replaces any / with \\. Then I call a method and pass the array to it, which puts the argument into a new array,...
Jon Skeet
people
quotationmark

It sounds like you want: var moddedFiles = (string[]) files.Clone(); That will create a shallow copy of the array, which is largely equivalent to a deep copy when it comes to strings, as they're immutable. However, a cleaner (IMO)... more 11/14/2013 4:28:59 PM

people

Convert.ToSingle() from double in vb.net returns wrong value

Here is my question : If we have the following value 0.59144706948010461 and we try to convert it to Single we receive the next value: 0.591447055 As you can see this is...
Jon Skeet
people
quotationmark

As you can see this is not that we should receive. Why not? I strongly suspect that's the closest Single value to the Double you've given. From the documentation for Single, having fixed the typo: All floating-point numbers have... more 11/14/2013 3:10:21 PM

people