Browsing 7239 questions and answers with Jon Skeet

Can't seem to change properties of objects in winforms C#

This is a bit of a confusing scenario. Basically, I'm trying to set a button's color when I use setter for a private variable that I store its color in. First off, I have a...
Jon Skeet
people
quotationmark

Did I do something wrong? Yes. Your setter is just fetching the existing property value: this.btn_input.BackColor = buttonColor; this._buttonColor = buttonColor; You meant to use value, which is the implicit parameter name for the... more 5/17/2017 6:13:04 PM

people

Cannot convert dbconnection to sqlconnection

I have created a generic method which will work with all database like sql server,mysql and oracle and execute my sql query and return datatable. private Datatable GetData(string...
Jon Skeet
people
quotationmark

Basically, when you call new SqlCommand(), that will only work with a SqlConnection. It's not going to work for MySqlConnection, or for anything from Oracle etc. SqlCommand is tightly coupled to SqlConnection. So either you need a... more 5/16/2017 12:35:05 PM

people

Where do 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