Browsing 15711 questions and answers with Jon Skeet

Where are Java exceptions came from?

Until now, I thought that every Java exception has to be created somewhere by a constructor, as I can create on my own, custom exceptions: Throw new Exception(); But now it...
Jon Skeet
people
quotationmark

The exception being declared isn't about what that implementation can throw - it's about what that implementation or the implementation in subclasses can throw. Service is an abstract class - and so are the two direct subclasses... more 5/16/2017 11:32:09 AM

people

ZoneId and LocalDateTime

I am running this piece of code in Paris right now, where its 12:40, where ECT = ECT - Europe/Paris LocalDateTime creationDateTime = LocalDateTime.now(Clock.systemUTC()); ...
Jon Skeet
people
quotationmark

No, you shouldn't. You've asked for a ZonedDateTime with the same LocalDateTime that you started with, but associated with a particular time zone. From the docs for LocalDateTime.atZone: This returns a ZonedDateTime formed from this... more 5/16/2017 10:51:08 AM

people

Why is `this` not available in C# 6.0 Auto Property Initialization?

I have the following code class: public class Foo { public Nested Bar { get; } = new Nested(this); public class Nested { public Nested(Foo foo) { ...
Jon Skeet
people
quotationmark

Why is it so? Isn't Auto-Property Initializer actually translated into constructor code in IL? The rules for automatically implemented property initializers are the same as those for field initializers, for the same reason. Note that... more 5/15/2017 10:33:24 AM

people

Why does BigDecimal divide cause rounding when it should fit within the significant digits?

Why does BigDecimal divide cause rounding to happen even though the value should fit comfortably in 4 significant digits? BigDecimal realPercent = new BigDecimal(1.25, new...
Jon Skeet
people
quotationmark

From the Javadoc of divide(BigDecimal, RoundingMode): Returns a BigDecimal whose value is (this / divisor), and whose scale is this.scale() The last part is important - the scale of your initial value is 2 (the unscaled value is... more 5/15/2017 8:32:00 AM

people

Is there anyway to get MethodDeclarationSyntax based on InvocationExpressionSyntax in Roslyn?

I want to write code refactor by roslyn so I wrote a code like class Program { [Obsolete()] public static void A() { } static void Main(string[] args) { ...
Jon Skeet
people
quotationmark

I suspect you just want to get the semantic model, ask it for the symbol, and get the attributes: // After you've made sure that you've got an InvocationExpressionSyntax var model = await context.Document ... more 5/14/2017 6:46:34 PM

people

tying multiple events to one handler:a function with 2 object params

This is my handler function: protected static void textChange(object sender,Label labe1, EventArgs e) { var text = sender as TextBox; if...
Jon Skeet
people
quotationmark

Assuming you're trying to associate each text box with a different label, you'll need to write a method that constructs an EventHandler for the relevant label, e.g. public EventHandler CreateVisibilityHandler(Label label) { return... more 5/14/2017 11:38:39 AM

people

WPF async await

I'm trying to use async click event: private async void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show(Thread.CurrentThread.ManagedThreadId + " ...
Jon Skeet
people
quotationmark

You're explicitly starting a new task using Task.Factory.StartNew(). That's almost always going to run in a non-UI thread. The async/await way of doing this is not to start a new task on a different thread, not to use the dispatcher, and... more 5/13/2017 10:22:09 AM

people

Unary operator precedence in java

Now, according to this website, Unary post-increment has more precedence than Unary pre-increment. I presume it meant, that x++ is done before ++x. However, when tried with the...
Jon Skeet
people
quotationmark

I presume it meant, that x++ is done before ++x. No, it doesn't mean that. I've previously blogged about how I find viewing precedence in terms of execution order is problematic. It may well be valid in a computer-science-strict way,... more 5/12/2017 2:40:14 PM

people

Convert json object to model if that object is dynamic

I need the solution to convert json object to model if that object is number and i want to access the fields of that object. {"threaded_extended": { "857334186": [ { "id":...
Jon Skeet
people
quotationmark

Your question is somewhat unclear, but I suspect I see the pattern - the value of threaded_extended is effectively a Dictionary<int, List<Post>> or similar. So that's how you should represent it: public class Root { ... more 5/12/2017 6:03:43 AM

people

Ordering a string list by an index list in c#

I have two list, one contains string data and the second one contains some index numbers. List<int> myIndexList = new List<int>() {4, 3, 1, 2, 5,...
Jon Skeet
people
quotationmark

I think you just want: var orderedByIndexList = myIndexList.Select(index => myValuesList[index]); If you need it as a List<T>, put .ToList() at the end. Note that this doesn't modify myValuesList - it just creates a new... more 5/11/2017 2:48:07 PM

people