You searched for jon skeet. We found 71 results in 0.068 seconds.

var array = new [] {d, "hello"} is implicitly typed to dynamic[] and not string[] ? why?

dynamic d = 5; var array = new[] {d,"hello"} What is the implicit type of array ? It is dynamic[] but not string[], why ? While going through C# in depth - Jon Skeet stated a...
Jon Skeet
people
quotationmark

For the most part, you can ignore this detail. But if you look through the specification, you'll see various place that the language considers conversions from type X to type Y. There are other places that the language considers... more

people

Is it possible to create a deadlock in C# if nothing but the lock keyword is used around primitive data access?

I've written a lot of multi-threaded C# code, and I've never had a deadlock in any code I've released. I use the following rules of thumb: I tend to use nothing but the lock...
Jon Skeet
people
quotationmark

Yes, it's easy to deadlock, without actually accessing any data: private readonly object lock1 = new object(); private readonly object lock2 = new object(); public void Method1() { lock(lock1) { Thread.Sleep(1000); ... more

people

Declaring a 2D array without knowing its size in C#

I would like to use a 2-D array but I can't know its size in advance. So my question is: how to declare it? And then how to add values into it? String[,] tabConfig = new...
Jon Skeet
people
quotationmark

So my question is: how to declare it? You can't. All arrays in .NET are fixed size: you can't create an array instance without knowing the size. It looks to me like you should have a List<T> - and I'd actually create a class... more

people

Reference to an object of any class that implements two or more given interfaces

Given any interface I, it is possible to declare a variable that holds a reference to any object of a class C that implements I: I i = new C(); I want to do something similar....
Jon Skeet
people
quotationmark

Given two interfaces, I want to declare a variable that holds a reference to any object of a class that implements both interfaces Unfortunately you can't do that. You can do so for a parameter in a generic method, like this: public... more

people

ArrayList One loop sorted, the other unsorted

For this assignment I need to sort one list and also keep the original list, but when I click the button twice, the original list is also sorted. String output = ""; ...
Jon Skeet
people
quotationmark

I suspect you just want to take a copy of the list, then sort that: List<Song> sortedSongs = new ArrayList<Song>(song); Collections.sort(sortedSongs); // Will not affect song Note that this should be done before your loop,... more

people

.Net 4.0 Optimized code for refactoring existing "if" conditions and "is" operator

I have following C# code. It works fine; but the GetDestination() method is cluttered with multiple if conditions by using is operator. In .Net 4.0 (or greater) what is the best...
Jon Skeet
people
quotationmark

Here's one option: private static readonly Dictionary<Type, string> DestinationsByType = new Dictionary<Type, string> { { typeof(Manager), @"\ManagerHome" }, { typeof(Accountant), @"\AccountantHome" }, //... more

people

C# is not able to convert my Character to String in a Foreach loop

I am using a simple code to read the JSON data. I previously needed some help in that, but I am able to overcome the exception through a Google search about the error. But this...
Jon Skeet
people
quotationmark

You're using foreach on a string. Effectively: string x = "foo"; foreach (string y in x) That makes no sense - a string is a sequence of characters, not a sequence of strings. In order to get the code to compile, you could just remove... more

people

C# Singleton Thread safe variables

I have referred to Jon Skeet's article here (http://csharpindepth.com/articles/general/singleton.aspx), the sixth version. However, I have some private variables that I want...
Jon Skeet
people
quotationmark

This is the problem: string _plantCode = appSettings["PlantCode"] ?? "Not Found"; That isn't assigning to the instance variable - it's declaring a new local variable. You just want: _plantCode = appSettings["PlantCode"] ?? "Not... more

people

NUnit Gets Different Hash Code Values from ReSharper vs Visual Studio 2013

I have a fairly simple GetHashCode() implementation in C# as per Jon Skeet's answer here. Here is my code: public override int GetHashCode() { unchecked { int...
Jon Skeet
people
quotationmark

You're probably using the 32-bit CLR in one test runner and the 64-bit CLR in another. The implementation of string.GetHashCode differs between the two. You should not depend on them being consistent between runs - they only have to be... more

people

XML XDocument There appears to be no elements

I'm trying to understand XDocument and it's various methods. I have a site map, and I'm trying to read the URLs <urlset...
Jon Skeet
people
quotationmark

How do I iterate over the loc values? The simplest way is to use the overload of Descendants which accepts an XName: foreach (var loc in siteMap.Descendants("loc")) { string value = loc.Value; ... } Currently, you're asking... more

people