Browsing 7239 questions and answers with Jon Skeet

Java Calculate with crazy large numbers

How can I calculate with very large numbers in Java. When I say crazy, I mean like 8192 bits integers and floats. Is this possible and what is the maximum an ordinary 64 bit...
Jon Skeet
people
quotationmark

When I say crazy, I mean like 8192 bits integers and floats. That's really not that crazy. It's not like that's going to tax the memory in your machine or anything. Use BigInteger for integers, and BigDecimal for floating point... more 1/16/2015 10:43:23 AM

people

Enums, What's the use of static methods and implementing interface methods?

I am having some small doubts regarding Enums. I have the following confusions :- What is the use of static methods in Enums? Mostly we use Enums for declaring constants. What...
Jon Skeet
people
quotationmark

What is the use of static methods in Enums? Same as in any other type. For enums, they're often "given this string value, return the equivalent enum" or something similar. (In cases where valueOf isn't appropriate, e.g. where there... more 1/16/2015 10:22:57 AM

people

Use LINQ to compare the date part of DateTime

I want to filter some documents between a different date. First I tried comparing the dates directly, but the time (hour, minutes, second) doesn't have to be considered. Therefore...
Jon Skeet
people
quotationmark

Just use the DateTime.Date property: if (fromDate.HasValue) { filterResults = filterResults .Where(d => d.LastModifiedAt.Date >= fromDate.Value.Date); } if (toDate.HasValue) { filterResults = filterResults ... more 1/16/2015 9:31:28 AM

people

how to write Custom JSon serializer in C#

I am using Newtonsoft json serializer to convert json string into objects. I have json structure as below - { "EmployeeRecords": { "12": { "title":...
Jon Skeet
people
quotationmark

You can easily do this with LINQ to JSON (JObject and friends). Here's a short but complete example: using System; using System.Collections.Generic; using Newtonsoft.Json.Linq; public class Employee { public string EmployeeNumber {... more 1/16/2015 7:35:42 AM

people

Can i store a UInt32, Int32 and a float value inside a double without losing information?

I need to save UInt32, Int32 and float values inside a variable. Can I use double without losing information (e.g. losing some digits in the conversion) or do I need to use a...
Jon Skeet
people
quotationmark

Being able to store the maximum value of UInt32 without losing information doesn't necessarily mean you'll be able to store all values in UInt32 without losing information - after all, there are plenty of long values which can be stored in... more 1/16/2015 7:14:51 AM

people

Error creating Roslyn SDK Template Project

Trying to create a Diagnostic with Code Fix (NuGet + VSIX) project on the latest VS2015 CTP release. After I try to create the project I get the following errors: Any idea...
Jon Skeet
people
quotationmark

When you create the project, make sure you set the .NET Framework version to 4.5, not 4.5.3. (I've run into exactly this problem before, and setting the version to 4.5 fixed it. I believe this is a known issue, and I'd expect at least a... more 1/16/2015 7:04:53 AM

people

convert a linkedlist to an typed array

This should be a relatively straightforward question. But I've got this code where I want to convert a linked list to a typed array. I think it should work, but it's not compiling...
Jon Skeet
people
quotationmark

Basically you're using the wrong overload of toArray. You want the one accepting an array T[], which is declared to return a T[] as well. It uses the execution-time type of the array to work out the type of array to create - it can't do... more 1/16/2015 6:55:55 AM

people

Unexpected output with RandomAccessFile

I'm trying to learn about RandomAccessFile but after creating a test program I'm getting some bizarre output. import java.io.File; import java.io.IOException; import...
Jon Skeet
people
quotationmark

You've written "Hello World" in the platform default encoding - which is likely to use a single byte per character. You're then reading RandomAccessFile.readChar which always reads two bytes. Documentation: Reads a character from this... more 1/15/2015 8:48:02 PM

people

Why do I have to cast results from dynamic coming into typed parameters

I have a simple dynamic object that returns a double: class MyDynamic : DynamicObject { public override bool TryGetMember(GetMemberBinder binder, out object result) { ...
Jon Skeet
people
quotationmark

I would have expected the runtime to automatically cast the returned value to whatever the type requested by the method is (int, in this instance). Why would you expect it to do that? There's no implicit conversion from double to int... more 1/15/2015 5:18:03 PM

people

Prevent instantiating derived class from anywhere except based class in C#

public abstract class Vehicle { public static GetVehicle() { if (Context.IsMountain()) { return new Truck(); } else { ...
Jon Skeet
people
quotationmark

The simplest approach is probably to make your implementations private classes inside the base class: public abstract class Vehicle { public static Vehicle GetVehicle() { if (Context.IsMountain()) { ... more 1/15/2015 5:07:49 PM

people