Browsing 7239 questions and answers with Jon Skeet

The type of the arguments cannot be inferred usage Linq GroupJoin

I'm trying to make a linq GroupJoin, and I receive the fore mentioned error. This is the code public Dictionary<string, List<QuoteOrderline>>...
Jon Skeet
people
quotationmark

I suspect this is the immediate problem: (q => o) => new { ... } I suspect you meant: (q, o) => new { ... } In other words, "here's a function taking a query and an order, and returning an anonymous type". The first syntax... more 10/24/2013 2:10:26 PM

people

Will c# compiler optimize empty if blocks

Is there a chance that C# will optimize the following code block? if (specField == null || AddSystemType(specField, layout) || AddEnumType(specField,...
Jon Skeet
people
quotationmark

Well you can use ildasm to see what the compiler has optimized for yourself. But if you were expecting it to remove the code entirely, it can't - because those three method calls could throw exceptions or modify state. So the best it could... more 10/24/2013 1:48:24 PM

people

Storing Count value from query

How do I store the returned count value into a variable, so I can then set a attribute with it? This is my method so far: public List<Sighting> total() { return...
Jon Skeet
people
quotationmark

You could either specify a name for the count, e.g. return jdbc.query("select pest_name, count(pest_name) as pest_count from sighting group by pest_name", new RowMapper<Sighting>() { public Sighting mapRow(ResultSet rs, int... more 10/24/2013 1:34:27 PM

people

Parsing XML data in C#

I have a xml data like this string data = @"<DeliveryReport><message id=""093102403501103726"" sentdate=""2013/10/24 08:50:11"" donedate=""2013/10/24 08:50:12"" ...
Jon Skeet
people
quotationmark

You're using XDocument.Load(string), which accepts a filename or URL to load the XML from: Parameters uri: A URI string that references the file to load into a new XDocument. You want XDocument.Parse(string), which accepts XML... more 10/24/2013 1:16:02 PM

people

Can't we have extension methods with same name for different classes?

I have two extension methods like this.. One is public static BsonValue TopOne(this IEnumerable<BsonValue> IEnumBv) { } Second One is public static...
Jon Skeet
people
quotationmark

You can absolutely do this - but you'll have problems if you try to call the extension method on something which is both a BsonValue and an IEnumerable<BsonValue>. For example: BsonArray array = ...; BsonValue top =... more 10/24/2013 7:42:28 AM

people

Confused about traversing a class hierarchy with polymorphism

Say I have a superclass called Fish, and a subclass called Tuna. I don't understand why this works: Fish f; Tuna t = new Tuna(); f=t; // I am confused about this...
Jon Skeet
people
quotationmark

The value of the f variable is a reference. That can be a null reference, or a reference to any object which "is a fish". As a Tuna object is a Fish object, it's fine to copy the value from t, which must either be a null reference or a... more 10/24/2013 6:33:34 AM

people

How to i write an Mp3 file Data into multiple byte arrays in java?

I am trying to read an Mp3 file from USB and write the data into different buffers. Please help me if there's any good way to do this. I could read the whole data into a byte...
Jon Skeet
people
quotationmark

Firstly, splitting a large file into buffers that small will be incredibly wasteful of memory. The overhead for each object will be about the same size (or greater than) the data itself. However, the idea of splitting an input stream into... more 10/24/2013 6:20:37 AM

people

Using XhtmlTextWriter with XmlTextReader

After reading this article, I have decided to update the following code (using XmlDocument) with XmlReader: Rendering controls public string Rendering(Control baseControl) { ...
Jon Skeet
people
quotationmark

Is there a room for optimizing the existing code? Absolutely. The first place I'd change has nothing to do with how you load the XML - it's string concatenation. I'd change your recursiveOperation method to: private static string... more 10/24/2013 6:05:56 AM

people

C# Web Service Return then Finally What happens first

In C#.NET, let's take the following example [WebMethod] public int TakeAction() { try { //Call method A Return 1; } catch (Exception e) { //Call...
Jon Skeet
people
quotationmark

The return value is evaluated first, then the finally block executes, then control is passed back to the caller (with the return value). This ordering is important if the expression for the return value would be changed by the finally... more 10/23/2013 9:29:05 PM

people

How to synchronize parallel actions in .NET?

I would like to accomplish the following: void Method() { Parallel.For(0, 100, i => { // Do first set of actions // Wait for all tasks to finish...
Jon Skeet
people
quotationmark

I would suggest you do exactly as per your second code snippet, but keep an array for these newly created objects - populate them in the loop, and access them in the second. void Method() { var intermediates = new Intermediate[100]; ... more 10/23/2013 9:19:51 PM

people