Browsing 7239 questions and answers with Jon Skeet

Unable To Overload != Operator Due To Error 3 requires a matching operator?

Unable To Overload != , Error 3 The operator 'ConsoleApplication13.pl.operator !=(ConsoleApplication13.pl, ConsoleApplication13.pl)' requires a matching operator '==' to...
Jon Skeet
people
quotationmark

Yes - C# requires that if you overload the != operator, you also overload the == operator. From the C# 5 specification, section 10.10.2: Certain binary operators require pair-wise declaration. For every declaration of either operator... more 12/4/2015 7:12:39 AM

people

How does a Property type passed to a function set the parameter value

I'm looking at a solution for getting the class name of a calling method in .Net 4.5 and I'm hoping to use a custom property attribute to implement it. Here is an example of using...
Jon Skeet
people
quotationmark

You can't, basically. The C# compiler has special knowledge of the CallerMemberName attribute - it doesn't have special knowledge of your attribute. It sounds like you should just be able to use CallerMemberName though, rather than having... more 12/3/2015 5:12:46 PM

people

C# JSONConvert Changing float value?

Im consuming a Web API using JSON , where one of the properties of the object I am bringing back is of type FLOAT. After inserting the data into the database I started noticing...
Jon Skeet
people
quotationmark

A float only has 7 digits of precision - that leading to the problem you're seeing. You can see this without getting JSON involved at all: using System; class Program { static void Main(string[] args) { float f =... more 12/3/2015 1:48:36 PM

people

Properties should not return arrays

Yes, I know this has been discussed many times before, and I read all the posts and comments regarding this question, but still can't seem to understand something. One of the...
Jon Skeet
people
quotationmark

If at any time the property is referenced it needs to allocate memory for a new ReadOnlyCollection that encapsulates the array, so what is the difference (in a manner of performance issues, not editing the array/collection) than simply... more 12/3/2015 12:11:08 PM

people

Add 10 minutes to the current timestamp in java with clipping milliseconds not working

I have the following code for finding the current timestamp in java public static java.sql.Timestamp getCurrentJavaSqlTimestamp() { java.util.Date date = new...
Jon Skeet
people
quotationmark

It looks like all you want is a way of truncating a Timestamp to remove the milliseconds part. I believe that's as simple as: timestamp.setNanos(0); more 12/3/2015 9:28:47 AM

people

C# awaitable problems

documents is a IDictionary<string, string> where the parameters are <filename, fileUrl> DocumentHandler.Download() returns a Task<Memorystram> This code...
Jon Skeet
people
quotationmark

Your keys variable will create a new set of tasks every time you evaluate it... so after waiting for the first set of tasks to complete, you're iterating over a new set of unfinished tasks. The simple fix for this is to add a call to... more 12/3/2015 9:25:48 AM

people

Why this prime number finding code is producing different results over iterations?

I have a simple code that finds all prime numbers between 1 and 100000. The problem is, it's not precise. There are 9592 primes between 1 and 100000 but I'm getting values...
Jon Skeet
people
quotationmark

You're adding to List<T> from multiple threads. That isn't supported without synchronization. If you add some locking, you may well find it works... but it would be simpler to use parallel LINQ instead. Something like this: using... more 12/3/2015 7:49:05 AM

people

Trying to reproduce "must declare a body" compiler error

I'm trying to reproduce the C# compiler error CS0840 with the exact code that's given in the website: class Test36 { public int myProp { get; } // CS0840 // to create a...
Jon Skeet
people
quotationmark

You're using Visual Studio 2015, which implements C# 6. The fact that you're targeting .NET 4 is irrelevant - most of the C# 6 language features don't depend on framework features at all. The C# 6 code you're using can easily be compiled... more 12/3/2015 7:39:36 AM

people

When I call a method, why isn't the overridden method called?

My problem is that my method call function goes to the virtual method, not to the overridden one. I tried to inherit the class with the virtual method and when I debug it's...
Jon Skeet
people
quotationmark

You're creating an instance of Engine, not Program - all you need to do is change the first line of Main to: Engine engine = new Program(); The implementation to use is based on the execution-time type of the object on which the method... more 12/2/2015 5:24:06 PM

people

Linux server showing UTC instead of EST, local showing EST

I am having trouble figuring out why the timezone for the code below keeps showing UTC instead of EST. On my local computer it show EST, even if I am in MST time but on the...
Jon Skeet
people
quotationmark

You've set the calendar to EST, but you haven't set the time zone on the SimpleDateFormat, which is the one use for formatting. Just use: format.setTimeZone(TimeZone.getTimeZone("America/New_York")); before you format the Date. You also... more 12/2/2015 3:27:41 PM

people