Browsing 7239 questions and answers with Jon Skeet

What happens at compile time when you try to cast a LinkedList to a LinkedList<String>?

In the following, I get a runtime exception on line 5, not on line 4. What is that cast actually doing? Any insight or links to relevant reading would be awesome. List list = new...
Jon Skeet
people
quotationmark

What is that cast actually doing? Nothing, at execution time. That's why you'll get a warning saying that it's an unchecked cast - it's not really checking anything, because the object itself (at execution time) has no concept of... more 11/1/2014 8:48:29 AM

people

How can I use XmlNode and XxmlNodelist in Windows Phone 8?

I have class was written by C#, It used XmlNode and XmlNodelist to read XML file. But When I bring it to my WP8 project, It's didn't support XmlNode and XmlNodelist. What should I...
Jon Skeet
people
quotationmark

What should I do? You should use LINQ to XML (XDocument etc) instead. It's a far superior XML API. Once you've ported your code to use it, ditch the XmlNode (etc) code entirely - use LINQ to XML in both your desktop and mobile code.... more 11/1/2014 8:30:19 AM

people

explicit lock vs implicit lock implementation

two example scenarios: first: public synchronized void foo1(){ ..... } public void foo2(){ ..... } and the threads loop is: public void run() { ...
Jon Skeet
people
quotationmark

if i run 10 threads, and one of these acquire lock inside foo1() other threads which want to execute foo1 will wait outside foo1() or they can loop and execute code inside foo2? Assuming they're being called on the same object,... more 11/1/2014 8:25:55 AM

people

C# equivalent of Java Class<? extends Base>?

I'd like to be able to write a method in C# similar to how I would in Java... To pass in a Class object that is a subclass of some super class... but the best I can find for C# is...
Jon Skeet
people
quotationmark

As others have said, you can do this with a generic type parameter... but if you only have the value as a Type and want to pass it in as a regular argument (e.g. because it's been passed to your method that way), there's no way of doing... more 11/1/2014 1:37:18 AM

people

Concatenate two org.w3c.dom.Document

I would like to concatenate two org.w3c.dom.Document s, I have something like this: Document finalDocument =...
Jon Skeet
people
quotationmark

As you say, you need to have a single root node - and you need to import the other documents. For example: Element root = finalDocument.createElement("root"); finalDocument.appendChild(root); root.appendChild( ... more 10/31/2014 6:51:14 PM

people

How to count all defined childforms with C#

I tried to use Count() or Length to count how many Can_ListCandidate childfrom are opening. Then, if there is only 1 form run, it is still keeping. While if the number is more...
Jon Skeet
people
quotationmark

It's somewhat unclear to me what you're trying to do, but if you want to count with a predicate, you could use: int count = MdiChildren.OfType<Can_ListCandidate>().Count(); which includes subclasses or int count =... more 10/31/2014 6:46:47 PM

people

Final doesn't let me change properties

I'm trying to change my components properties. Like setting their alignment to right or left. I have 15 buttons on FlowLayout panel. final FlowLayout exL = new...
Jon Skeet
people
quotationmark

I think I can't change my buttons' properties No, that's not true. final applies to the variable, that's all. It doesn't prevent changes to the object. In other words, this would be invalid: exL = new FlowLayout(...); // Trying to... more 10/31/2014 6:21:02 PM

people

Use of unassigned out parameter 'q'

Getting error use of unassigned out parameter 'q' and 'g', please correct where I am doing wrong. Thanks in advance. using System; using System.Collections.Generic; using...
Jon Skeet
people
quotationmark

What you're doing wrong is exactly what the compiler says you're doing wrong - you're trying to read from an out parameter before it's definitely assigned. Look at your code: static void Fun(out int q, out int g) { q = q + 1; ... more 10/31/2014 6:10:31 PM

people

How to compare Lists of Guids in C#

I have got this structure var values = new Dictionary<int, List<Guid>>(); And I have to say if all dictionary elements has the same set of List<Guid>. I dont...
Jon Skeet
people
quotationmark

I'd create a HashSet<Guid> from one of the values (any) and then check that all of the others are equal to it: // TODO: Handle the dictionary being empty var firstSet = new HashSet<Guid>(values.First().Value); var allEqual =... more 10/31/2014 3:47:30 PM

people

Why do I need 2 Console.ReadLine(); to pause the console?

I'm just learning c#, and I like to understand everything before I move on. The problem I'm having is I need 2 Console.ReadLine(); to pause the console. If I just use 1, the...
Jon Skeet
people
quotationmark

You're using Console.Read(), which reads a single character after the user has hit return. However, it only consumes that single character - which means the rest of the line (even if it's empty) is still waiting to be consumed... which... more 10/31/2014 3:06:30 PM

people