Browsing 7239 questions and answers with Jon Skeet

Return data in Json format with object name

Wrote a simple function for Web API 2 which returns the list of countries. It returns the valid Json format but without the array/object name. I have a bit of difficulty...
Jon Skeet
people
quotationmark

You could either create a specific class for this, as per the answer from Boas, or just use an anonymous type: return Ok(new { CountryList = list }); Basically, you need an object with the appropriate property, one way or the other. If... more 11/27/2015 9:50:24 AM

people

Variable inside thread is null at some point

I have an ArrayList that I am accessing in a Thread inside onStart method in JavaFX. When I am trying to access the ArrayList from another Thread again in a method that is...
Jon Skeet
people
quotationmark

Now that we've finally got a repro, the problem is simply that menuItemActionMethod is being called on a different instance of Main to the start method. Not being a JavaFX developer, I can't easily follow the code flow here, but you can... more 11/27/2015 9:34:17 AM

people

Reducing linq and convert C#2005

I want to reducing linq code below and convert C# 2005 private void cmdCaculator_Click(object sender, EventArgs e) { int rowcount = gridView1.RowCount; ...
Jon Skeet
people
quotationmark

There's no LINQ in that code - just a lambda expression. You can use an anonymous method instead: private void cmdCaculator_Click(object sender, EventArgs e) { int rowcount = gridView1.RowCount; Thread myThr = new... more 11/27/2015 7:44:15 AM

people

How does C# know what type the literal is?

Consider this code: double i = 0xF0000000; Console.WriteLine(0xF0000000.GetType()); Console.WriteLine(i.GetType()); Why C# prints System.UInt32 for first one and System.Double...
Jon Skeet
people
quotationmark

In this line: double i = 0xF0000000; the literal is of type uint, but it's being implicitly converted to a double. When you call i.GetType() that would always print System.Double, because the variable is of type double... the only kind... more 11/27/2015 6:51:46 AM

people

Java is clearly a pass by value but wanted some clarification

Have read a lot of stack overflow answers on this topic and also I have read many blogs. I can surely conclude that Java is pass by value. But to convince people I need a proof...
Jon Skeet
people
quotationmark

I don't know any languages which are pass-by-reference all the time, but C# has the ref modifier which allows a specific parameter to use pass-by-reference. That allows you to see the difference pretty easily. For example: using... more 11/26/2015 8:38:03 AM

people

define a dynamically evaluated formula for a local variable

I was looking at a piece of error handling code that looks like this: if (condition) { thereIsAProblem = true; problemDescription = "x"; } if (!thereIsAProblem...
Jon Skeet
people
quotationmark

Not quite... but you could make it a delegate instead: Func<bool> thereIsNotAProblem = () => { /* some expression */ }; Console.WriteLine(thereIsNotAProblem()); // true thereIsAProblem =... more 11/25/2015 4:30:13 PM

people

Why property changed value is null after changing the property value?

Can anyone tell me why PropertyChanged value comes null in INotifyPropertyChanged. I have a property and I change its value, but when it enters in NotifyPropertyChanged method the...
Jon Skeet
people
quotationmark

but when it enters in NotifyPropertyChangd method the value of PropertyChanged is null That just means that nothing has subscribed to the event yet. Beyond events, a delegate instances refers to one or more actions to execute when the... more 11/25/2015 9:52:38 AM

people

Decryption negating special character like " !@#$%^&*()"

I was wondering how am i able to negate away the special character. For example when i key aaa for my decrypted text and move 3 space behind, it shows it ^^^ instead of www. Is...
Jon Skeet
people
quotationmark

The problem is with this piece of code which does the actual shifting: if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { temp = (int)(a[i] + shift); if ((c >= 'A' && c <= 'Z'... more 11/25/2015 7:16:39 AM

people

sbyte[] can be magically cast to byte[]

I'm not sure whether this is a .NET bug but I find it really interesting. As expected, I cannot do this: sbyte[] sbytes = { 1, 2, 3 }; byte[] bytes = sbytes; // fails: cannot...
Jon Skeet
people
quotationmark

No, it's not a bug. It's just an impedance mismatch between the C# language rules (which claim there's no conversion available) and the CLR rules (where the conversion is available). Note that the compiler really, really thinks it knows... more 11/24/2015 2:35:53 PM

people

Reflection C# Activator returning a null value

Please I don't know what I am doing wrong, when I run this code, I get an exception: Value cannot be null.... When I run it in debug mode, I see that "calculatorInstance" variable...
Jon Skeet
people
quotationmark

I'm pretty sure it's actually the GetType method which is returning null - because there's no type with the fully-qualified name ReflectionWithLateBinding.Calculator. Your Calculator class is nested within your Program class. It's the... more 11/24/2015 2:32:32 PM

people