Browsing 7239 questions and answers with Jon Skeet

Saving output to files

I currently am trying to put the values that are created through my object into a file. My output for the program works fine and my computations in another class's methods work. I...
Jon Skeet
people
quotationmark

You're not closing your streams - which are explicitly buffered. So everything is in memory, and you never gets flushed to disk. Use a try-with-resources statement to close everything appropriately, even if an exception is thrown.: try... more 4/24/2015 4:28:03 PM

people

Which are the default modifiers for fields and methods in a Java annotation?

Which are the default modifiers for x and m in public @interface Anno { int m() default x; int x = 10; } ? I suppose that the code above is equivalent to: public...
Jon Skeet
people
quotationmark

Yes, I believe you're right - and the one bit of documentation I've found to support this is in JLS 9.6: Unless explicitly modified herein, all of the rules that apply to normal interface declarations apply to annotation type... more 4/24/2015 2:38:59 PM

people

Cannot convert from 'void' to 'byte[]'

I'm trying to do this: public string getName(uint offset, byte[] buffer) { return Encoding.ASCII.GetString(PS3.GetMemory(offset, buffer)); } But it returns me an...
Jon Skeet
people
quotationmark

Contrary to the other answer, I don't think you need to modify your GetMemory method, which looks like it's calling void methods (e.g. here). It looks like GetMemory writes into the buffer you provide, so you may just need: // Name... more 4/24/2015 2:10:35 PM

people

overload resolution in c#: Func<T> parameter

Writing this function: static TResult reduce<TSource, TResult>(ParallelQuery<TSource> source, Func<TResult>...
Jon Skeet
people
quotationmark

The problem is your third argument - the fourth parameter for in the method declaration. That's declared as: // Note: type parameter names as per Aggregate declaration Func<TAccumulate, TAccumulate, TAccumulate>... more 4/24/2015 1:16:17 PM

people

Get the real DateTime even if i changed clock on my host (c#)

I want to generate a serial number for an application (to be used just in a period of time), this serial number based on the time, so it's will be unnecessary code if change the...
Jon Skeet
people
quotationmark

am asking you if is there any possibility to get the real DateTime even if i changes time on my computer using C# ? (I assume that the user does not have an internet connection) No. The system clock is the local source of time... more 4/24/2015 11:19:02 AM

people

Since Array does not have For each is there an alternate way we can use LINQ to do some action

svc_Orders is an array of SVCORDER[] List<Order> local_order_list = new List<Order>(); foreach (var svc_Order in svc_Orders) { Order local_Order = new Order(); ...
Jon Skeet
people
quotationmark

If you want to project items from one type to another, that's what Select is for - then there's the ToList method: // Names changed to conform to .NET conventions var localOrderList = serviceOrders.Select(serviceOrder => new Order {... more 4/24/2015 10:43:01 AM

people

Casting string to double, dot gets removed

While casting from string to double, the dot gets removed, eg. for 0.01 after casting to double it gives 1, or for 3.22 it gives 322. Below is the Code I used. In log file I...
Jon Skeet
people
quotationmark

I strongly suspect this is indeed a culture issue - your thread's current culture probably uses . as a grouping separator rather than a decimal separator. In fact, in some cultures your code would just fail with an exception. Here's an... more 4/24/2015 10:34:14 AM

people

C# expression Lambda

Hi I'm learning about using Lambda from a book. After I copied a piece of code from the book to VS2010 I got the error: Delegate 'System.Func<float>' does not take 1...
Jon Skeet
people
quotationmark

You're trying to write a function which accepts a float input, and returns a float output. That's a Func<float, float>. (To give a clearer example, if you wanted a delegate with an int parameter and a return type of float, that would... more 4/23/2015 9:27:30 PM

people

Delegating general class to specific classes

I have the following interfaces: public interface IModel { ModelTypes ModelType { get; } // ModelTypes is an enum } public interface IModelConverter<T> { byte[]...
Jon Skeet
people
quotationmark

And I know the solution here should be using covariance on T in IModelConverter No, not really. That would only be the case if any specific IModelConverter could be regarded as a more general IModelConverter - and that's not the case.... more 4/23/2015 9:04:27 PM

people

Wrong SHA 256 hash of a string in MessageDigest

in some tests i using MessageDigest library in Groovy and sometimes this function returns incorrect value. Here is my code below: import...
Jon Skeet
people
quotationmark

You're missing a '0' at the start, because you're padding left to 40 characters (presumably having copied that code from something where the hash is expected to be 40 characters) instead of the 64 characters that actually makes up a... more 4/23/2015 6:28:13 PM

people