Browsing 7239 questions and answers with Jon Skeet

async Indexer in C#

Recently, we have movied to EF 6 and we have begun to use EF async commands. For example in my repository I have the following method: // Gets entities asynchron in a range...
Jon Skeet
people
quotationmark

You simply can't make indexers async. From section 10.15 of the C# 5 specification: A method or anonymous function with the async modifier is called an async function. async is listed as one of the valid modifiers for methods... more 3/4/2014 2:21:39 PM

people

Looping through xmlnodes using Xdocument

I have an xml string like this <Test> <ConnectionParameters> <ConnectionParameter DisplayName="asd" Id="cgfh" IsPassword="false" IsRequired="true"> ...
Jon Skeet
people
quotationmark

You're currently looping through all the ConnectionParameters elements (of which there's only one) and selecting the first ConnectionParameter element (using the Element call). You want to just loop through the ConnectionParameter... more 3/4/2014 2:01:44 PM

people

Delegates do not get garbage collected

Below is a console app that demonstrates the issue: class Program { static void Main() { InitRefs(); GC.Collect(); GC.WaitForPendingFinalizers(); ...
Jon Skeet
people
quotationmark

Your delegates don't capture anything, so the compiler basically caches them. You can see this in action with this short program: using System; class Program { static void Main() { Action action1 = GetAction(); ... more 3/4/2014 1:33:39 PM

people

Parsing a YouTube request

i have a problem while parsing youtube request. I want to extract the nodes from the response but my code returns always zero. this is the code snippet: public void...
Jon Skeet
people
quotationmark

The immediate problem is that you've ignored the intervening media:group element which contains the media:thumbnail elements. So you can change your XPath to: var title = xml.SelectNodes("/t1:entry/t2:group/t2:thumbnail", nsm); It's... more 3/4/2014 10:01:54 AM

people

How to capitalize every third letter ot a string in C#?

does anybody know how to capitalize every third letter of a string in C# ? I loop through the whole string with a for loop, but i can't think of the sequence right now. Thanks in...
Jon Skeet
people
quotationmark

I suspect you just want something like this: // String is immutable; copy to a char[] so we can modify that in-place char[] chars = input.ToCharArray(); for (int i = 0; i < chars.Length; i += 3) { chars[i] =... more 3/4/2014 7:27:53 AM

people

Using LINQ SequenceEqual extension method with occassionally null properties

I'm writing a simple console application that compares two instances of a custom class object. For each property, I'm writing True or False to the console window to show whether...
Jon Skeet
people
quotationmark

I'd probably add a NullRespectingSequenceEqual extension method: public static class MoreEnumerable { public static bool NullRespectingSequenceEqual<T>( this IEnumerable<T> first, IEnumerable<T> second) ... more 3/4/2014 7:21:19 AM

people

Java Servlet program to separate Image Strings using Array or Array List

In my java servlet program i am getting images from android application.I want to encode again decode image. If i got two images from android: [abc,def].It is decoded using...
Jon Skeet
people
quotationmark

All you need to do is call write appropriately with the text you want to write. For example: Writer writer = response.getWriter(); writer.write("["); for (int i = 0; i < r.length; i++) { if (i != 0) { writer.write(",");... more 3/4/2014 7:15:31 AM

people

How to override List.Add method?

Currently I have a error logging class like so: public class Log { public enum LogTypes { Info = 1, Error = 2, Warning = 3 } public...
Jon Skeet
people
quotationmark

Firstly, I wouldn't do this. It's not what anyone using a List<Log> would expect. Rather than exposing a plain List<Log>, consider creating a Logger class or something similar which contains a List<Log> and exposes a... more 3/4/2014 7:00:59 AM

people

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:

My method in the service and test class : public void updateSubModuleOrder(Long[] data, Long moduleSysId, Long userId) { try { for (int i = 0; i < data.length;...
Jon Skeet
people
quotationmark

You either have to specify no matchers, or all the arguments need matches. So this: when(userSubModuleDao.findById((any(UserSubModuleId.class)),false)) should be: when(userSubModuleDao.findById(any(UserSubModuleId.class),... more 3/4/2014 6:52:57 AM

people

Simple LINQ to XML

In C#, how can I select values from an XML file using LINQ? Here is my XML file: <?xml version="1.0" encoding="utf-8"?> <Level1> <Level2> ...
Jon Skeet
people
quotationmark

There are various things wrong with your current code: You're using Attribute when there aren't attributes in the XML You're trying to use the Value property on Descendants, but Descendants returns IEnumerable<XElement> You're not... more 3/3/2014 8:06:46 PM

people