Browsing 7239 questions and answers with Jon Skeet

XML Exception when compare with a number in SELECT with CASE statement

I used CASE statement in SELECT function as following: SELECT CASE WHEN a < 0 THEN 0 ESLE a END AS "Number 1" FROM <TABLE_NAME> This function...
Jon Skeet
people
quotationmark

If your XML file literally contains WHEN a < 0 then I'm not surprised you're getting an exception - that's not valid XML. It's got nothing to do with the SQL side of things as your attempted fix suggest. You should be escaping the <... more 11/6/2015 8:29:58 AM

people

How to get all IANA Timezones from an offset in NodaTime?

In our ASP.NET MVC 5 application we have user profiles with a Timezone ID (IANA). public class User { public int Id { get; set; } public string TimeZoneId { get; set;...
Jon Skeet
people
quotationmark

Simpler code for the "building a dictionary" that Serge shows: use LINQ's lookup, DateTimeZone.GetUtcOffset, and Offset keys instead of TimeSpan values: var now = SystemClock.Instance.Now; var provider = DateTimeZoneProviders.Tzdb; var... more 11/6/2015 7:06:07 AM

people

check if record exists in database using LINQ

I am getting a cast error here but I do not understand as to why. protected bool isPlayerdb(string userName) { try { Users adminUsers = from users in...
Jon Skeet
people
quotationmark

You're asking to assign a sequence value to single entity variable. That's like trying to do this: // Won't work for the same reason string name = new List<string> { "foo", "bar" }; If you're just trying to find out whether there... more 11/6/2015 6:53:15 AM

people

C# get and Thread class just work twice, I don't know exactly

namespace LEDServer { public class Weather { string weathervalue, weatherexplain, temperature; int temp; public void DoWork() { ...
Jon Skeet
people
quotationmark

I don't know why this program just work twice.. Because the default HTTP connection pool has a size of 2 connections per host - and you're using them both up. You can configure this with the <connectionManagement> element in... more 11/5/2015 4:50:04 PM

people

C# .Select(int.Parse), compiler error cs0411

I've just read this question: Convert string[] to int[] in one line of code using LINQ There was an array of strings: var arr = new string[] { "1", "2", "3", "4" }; And one of...
Jon Skeet
people
quotationmark

The short answer is: C# type inference and support for method group conversions has improved over time. You're still using the C# 3 compiler (which is what shipped in VS 2008). The exact details are tricky, and I can never remember exactly... more 11/5/2015 2:01:28 PM

people

Again on using interlocked

I read a lot of answers on this point but I did not found the solution yet. I have a class with a counter attribute having a problem with cached values. Even volatile don't seems...
Jon Skeet
people
quotationmark

You're effectively testing for the number of tasks that have actually started and got as far as incrementing the counter. That takes a little while - so basically you're creating all 8 tasks and starting them, then they're incrementing the... more 11/5/2015 1:46:41 PM

people

ArrayIndexOutOfBoundsException when using loop for creating JFormattedTextField

I want to create a few JFormattedTextFields but always get ArrayIndexOutOfBoundsException and I do not understand why. The variable globalZaehler2 is 51 and then I will get the...
Jon Skeet
people
quotationmark

We can't tell terribly easily, but the name globalZaehler2 makes it sound like this is a field, not a local variable. Using a field for an "index" variable in a for loop is almost always a bad idea... I can't remember the last time I... more 11/5/2015 12:27:28 PM

people

ToList<T>() vs ToList()

Does it make sense to specify a concrete type in ToList<T>(), AsEnumerable<T>(), etc methods? Will .ToList<SomeClass>() execute faster than just .ToList()?
Jon Skeet
people
quotationmark

It makes sense if the compiler infers one type and you want to specify another. It doesn't make sense otherwise. For example, suppose you have an IEnumerable<string> and want to create a List<T>... if you want a... more 11/5/2015 12:08:16 PM

people

Better way to write common function with parameter is different class

In my project, I have some functions like that: func 1 (with 2 class: class1 and classs1_1): List<class1> GetData1(class1_1 cls) { List<class1> list = new...
Jon Skeet
people
quotationmark

It sounds like you need: An interface or abstract base class with the GetSpecialCase method A generic method (with type parameters for both input and output) of List<TResult> GetData<T, TResult>(T item) where T :... more 11/5/2015 7:21:24 AM

people

Performance impact due to StackTrace constructor and getting method name

I have this piece of code in our logging library var stackTrace = new StackTrace(); string operationName = stackTrace.GetFrame(1).GetMethod().Name; And as per my performance...
Jon Skeet
people
quotationmark

As of C# 5, it would definitely be better to get the compiler to bake this into the call site instead, using [CallerMemberName] public void Log(string message, [CallerMemberName] caller = null) { } Then: public void DoSomething() { ... more 11/4/2015 5:39:40 PM

people