Browsing 7239 questions and answers with Jon Skeet

Application compiled in .Net 4 framework will not run on Server 2012

I compiled my application to use .NET Framework 4 because I need this to work on XP and Server 2003 that does not support .NET Framework 4.5. The issue is it now runs fine on the...
Jon Skeet
people
quotationmark

I strongly suspect this has nothing to do with the version of .NET you're using. After all, from the stack trace you can clearly see that your code is executing: at MyApplication.Form1.DirectoryExporter_Click(Object sender, EventArgs... more 9/5/2014 1:35:41 PM

people

Adding Complex Keys in the Dictionary! Does it effect the performance

I am just writing a program that requires Dictionary as (in C#.net-4.5) Dictionary<List<Button>, String> Label_Group = new Dictionary<List<Button>,...
Jon Skeet
people
quotationmark

In fact, the lookup based on a List<Button> will be faster than based on a string, because List<T> doesn't override Equals. Your keys will just be compared by reference effectively - which is blazingly cheap. Compare that with... more 9/5/2014 12:46:27 PM

people

C# Accessor and initialization

How can we combine c# accessor declaration and initialization List<string> listofcountries= new List<string>(); and List<string>listofcountries {get;set;} Is...
Jon Skeet
people
quotationmark

You can't at the moment. You will be able to in C# 6: List<string> Countries { get; set; } = new List<string>(); You can even make it a read-only property in C# 6 (hooray!): List<string> Countries { get; } = new... more 9/5/2014 12:36:01 PM

people

How can I write the following lambda expression in one line?

I want to fetch the records as follows SearchResult.condition is null then fetch all the rows from Person if SearchResult.condition is false then fetch the rows where...
Jon Skeet
people
quotationmark

Well you can do it with a conditional operator, but you need to specify the type of the expression tree for each lambda expression: var expression = condition == null ? (Expression<Func<Person, bool>>) a =>... more 9/5/2014 12:34:50 PM

people

C#: Generic method doesn't call specific method overload

I am trying to create a generic method in C#, which will call different methods based on the argument datatype in its body and process their result afterwards. I am trying to...
Jon Skeet
people
quotationmark

Is there any way correct this behavior? It's already the correct behaviour according to the C# language specification. The overload of Func called within FuncWrap is normally determined at compile time, so it can't pick a different... more 9/5/2014 12:05:25 PM

people

Java hashmap default size

Hi I have a situation where I have to store a single key value pair to my Hashmap . The map size is always constant. i.e., 1 . But default size of hash map is 16 bits . Here am...
Jon Skeet
people
quotationmark

You can provide an initial capacity in the HashMap constructor: Map<String> map = new HashMap<>(1); It looks like that is genuinely obeyed in the implementation I'm looking at, but I can easily imagine some implementations... more 9/5/2014 10:51:18 AM

people

Convert String into Blob

I'm new to JDBC and stack overflow as well, and what I'm trying to do here is this : I'm trying to insert a string as blob into a database but I'm getting null pointer exception....
Jon Skeet
people
quotationmark

A few possible problems: It's not clear why you're explicitly setting a parameter to null. Why not just specify the column names explicitly in the SQL (which will make it clearer) and omit that column/parameter? Although you're creating... more 9/5/2014 6:39:05 AM

people

How to compare two DateTimeOffSet?

I have a variable which is of type DateTimeOffSet. I'd like to filter all the projectS that were created after January 1st, 2010. So I've wrote the following query: var _date...
Jon Skeet
people
quotationmark

So is my above query still relevant? Yes. When you compare two DateTimeOffset values, it's the "absolute" time that is compared. The documentation talks about this in terms of the UtcDateTime property. For example, from the... more 9/4/2014 7:00:52 PM

people

Checking UInt16 for flags using Enum.HasFlag()?

I have a C#/.NET 4.0 application that receives and parses some data from a network connection. One particular piece of data that I need to parse is a UInt16 value that represents...
Jon Skeet
people
quotationmark

I assume that I need to convert the UInt16 into an instance of the Fields enum but I'm not sure how to do that. That's easy - you need to cast to the underlying type of the enum, and then you can cast to the enum itself: Fields value... more 9/4/2014 6:55:48 PM

people

Safe Navigation of indexed objects

With the introduction of Roslyn, C# gets the benefit of the Safe Navigation operator. This is brilliant for objects that use dot notations e.g. MyClass myClass = null; var...
Jon Skeet
people
quotationmark

Based on the Language Feature Status Page it looks like you want: var singleElement2 = myClass2?.ArrayOfStrings?[0]; The example on the page is: customer?.Orders?[5]?.$price ... admittedly the $price part has been withdrawn now, I... more 9/4/2014 4:50:41 PM

people