Browsing 7239 questions and answers with Jon Skeet

Path variable not staying set

I'm working on setting up my development environment in Windows 7, installing Maven, etc. I've been running into path issues and have read, ad nauseum, other posts that pointed me...
Jon Skeet
people
quotationmark

You're only setting it within that shell. This is perfectly normal behaviour for environment variables - not just on Windows, but on other OSes too. I don't know about Windows 7, but on Windows 8 if I press the Windows key and start... more 8/7/2014 9:52:52 PM

people

Two tasks are firing even when there's only one item, using async/await and Task.WhenAll

What's wrong with my code here? Even when items.count is only 1, the DoSomething method gets called twice, and counter is equal to 2. Have I not structured the awaits correctly...
Jon Skeet
people
quotationmark

You're using Select incorrectly, basically. It's lazy, remember? So every time you iterate over it (once for Count() and once in WhenAll)... it's going to call your delegate again. The fix is simple: just materialize the query, e.g. with... more 8/7/2014 8:15:21 PM

people

If a class is loaded multiple times, do its static members get initialized multiple times?

If a class is loaded multiple times, do its static-members get initialized multiple times? How do I check for that?
Jon Skeet
people
quotationmark

If there are different classloaders involved, then they will be completely separate classes, with separate static fields etc - and each will be initialized separately. (The simplest way to diagnose this is just to log when you get... more 8/7/2014 4:24:27 PM

people

Error Asserting two decimals

Can anyone help me understand, because the expected value and the actual value have different results in the ToString() method. When I open the watch for me it is the same...
Jon Skeet
people
quotationmark

Don't believe the Watch window, basically. It can play silly games with string representations of values. The two values are equal (expected == actual will be true), but they're not identical - the trailing zeroes are preserved. Here, the... more 8/7/2014 4:02:19 PM

people

switch over value of enum: case expressions must be constant expressions

I have an enum with the following structure: public enum Friends { Peter("Peter von Reus", "Engineer"), Ian("Ian de Villiers", "Developer"), Sarah("Sarah Roos",...
Jon Skeet
people
quotationmark

This seems perfectly legal to me Well it's not - a method call is never a constant expression. See JLS 15.28 for what constitutes a constant expression. And a case value always has to be a constant expression. The simplest fix would... more 8/7/2014 1:27:29 PM

people

Compare dates with deferent formats framework 4.5 c# web forms

A part of my project is to write a function that will generate an increasing number for every day for every record I have to store in a database table. My problem is that when I...
Jon Skeet
people
quotationmark

I suspect you just want: DateTime today = DateTime.Today; // Just fetch the date part. var query = context.vehicles.Where(v => v.InsertionDate == today); Avoid string conversions if you possibly can. If your InsertionDate includes... more 8/7/2014 11:36:27 AM

people

What exactly is the type of a lambda expression with a body?

Windows forms extension method Invoke() doesn't accept a lambda expression, without us having to first typecast it to a delegate type like Action. This makes me wonder, if lambda...
Jon Skeet
people
quotationmark

This makes me wonder, if lambda expression (with a body) is not explicitly a delegate nor an expression, what is its type? It doesn't have a type in the normal sense of the word (i.e. a CLR type), just like null doesn't have a type.... more 8/7/2014 10:14:41 AM

people

Multiplying two numbers using BigDecimal returns a wrong value

Executing the following code: new BigDecimal(0.06 * 3).toString() returns 0.179999999999999993338661852249060757458209991455078125 instead of 0.18. Executing new...
Jon Skeet
people
quotationmark

You're not multiplying two numbers using BigDecimal. You're multiplying them using double arithmetic, and passing the result to the BigDecimal constructor. You want: new BigDecimal("0.06").multiply(new BigDecimal("3")).toString() Note... more 8/7/2014 9:39:53 AM

people

Cant access a public variable from a public class anywhere in my solution (VS, C'#)

i have taken over a project and I am struggling to access a public variable from a public class. (Strange). I am relatively new to C# having only done some MVC, ASP.NET stuff so...
Jon Skeet
people
quotationmark

NewAlertCount is a property in a class - but we can't tell what that class is. (Maybe it's ProjectHeaderControl - your description is somewhat hard to understand.) Intelligence_Gathering_System.Pages.Project.Controls is a namespace. A... more 8/7/2014 9:05:23 AM

people

How to get UTC time based on a DateTime and a TimeZone Offset?

I have a datetime object, and I know the UTC offset (double). How can I get UTC time from these two pieces of information? All of the examples I've seen require a timezone. ...
Jon Skeet
people
quotationmark

Just use DateTimeOffset: TimeSpan utcOffset = TimeSpan.FromHours(timeZone); DateTimeOffset result = new DateTimeOffset(dateTime, utcOffset); DateTime utc = result.UtcDateTime; or string utc = result.ToString("yyyy-MM-dd'T'HH:mm:ssK",... more 8/6/2014 7:53:53 PM

people