Browsing 7239 questions and answers with Jon Skeet

How to format the current date with Suffix to Superscript?

I am using the SimpleDateFormatter public static final DateFormat DATE_FORMAT_FULL_FULL_SPACES = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()); and Current...
Jon Skeet
people
quotationmark

The superscript part isn't the first tricky part here - although it's not clear how you'd want that to be represented anyway (HTML with <sup> tags? something else?) The first tricky part is knowing how to get the ordinal (st, nd,... more 10/13/2014 10:34:23 AM

people

C# What is the speediest technique for IsStringMadeOf method?

I have a method which is called thousands of times, but it is currently very slow to run. Is there a better technique? Unsafe methods are allowed. It simply checks letters of...
Jon Skeet
people
quotationmark

To start with, you've got a lot of string operations here - you're creating lots of new strings by removing a single character each time, and you're using IndexOf a lot too. I would start very simply - just sort the characters in each... more 10/13/2014 8:05:43 AM

people

how to convert dynamic to list<dynamic>

i have a variable swimlaneAttribute: List<dynamic> swimlaneAttributes = new List<dynamic>(); but in a function i have a return type of dynamic public dynamic...
Jon Skeet
people
quotationmark

You're currently returning a sequence of anonymous type objects. That sequence can't be cast to a List<T> because it isn't a List<T>. You could change the declaration to: IEnumerable<dynamic>... more 10/13/2014 6:20:13 AM

people

Program Won't Read all of the data from the File

So the gist of my program is that it will read some commands from a file and then perform certain operations judging by the commands. My problem is that my code isn't reading all...
Jon Skeet
people
quotationmark

You're calling input.next() far too often here: if (input.next().equals("P")) { ... } else if(input.next().equals("R")) { ... } else if(input.next().equals("S")) { ... } ... By the time it's checked for S, it's read three... more 10/13/2014 6:16:49 AM

people

Protected function not accessible in derived class

I am making a simple C# console application to test inheritance but when I add 2 new classes and inherit one with another ( Mammal:Animal ) and make an object of mammal in the...
Jon Skeet
people
quotationmark

The code within Mammals has access to protected members of Animals, but only via an expression of type Mammals or a subtype. From outside the class - which I assume this is - there's no access to protected members. From section 3.5.3 of... more 10/13/2014 6:03:08 AM

people

C# Extract the local variable name of on an object. Not the generic class name

C# .net 4.5 Visual Studio 2013 Update 3 Windows NT 6.3 build 9200 (Windows 8.1 Home Premium Edition) i586 Looking for a method/process to extract the current local variable name...
Jon Skeet
people
quotationmark

An object doesn't have a name. A variable has a name, but multiple variables could have values which refer to the same object. For example: Beast monkey = new Beast(); Beast donkey = monkey; Now they both refer to the same object - so... more 10/12/2014 7:25:50 PM

people

SqlConnection.ServerVersion Exception after Close()

I open a SqlConnection. SqlConnection Conn = new SqlConnection(...); Conn.Open(); ... Conn.Close(); Conn.Dispose(); //debugger breakpoint When I look in my debugger at this...
Jon Skeet
people
quotationmark

Just avoid examining the connection object after you've disposed of it. ("Doctor, it hurts when I do this..." "Stop doing that then!") The easiest - and most reliable - way to do that is to use a using statement instead: using (var conn =... more 10/12/2014 7:20:58 PM

people

Call method on all items of a certain type in LINQ

So I have a collection of objects. The objects are of differing type, but all of the types derive from a single base class. I want to iterate through the collection, check for...
Jon Skeet
people
quotationmark

Deferred/immediate execution isn't relevant here. If you called ToList(), that wouldn't change anything. There are two options to make this simpler though. Firstly, if you don't need it to be the exact Dog type, but DogBeagle or anything... more 10/12/2014 1:57:52 PM

people

Representing signed byte in an unsigned byte variable

I apologies if the title of this question is not clear, but i cannot figure out the best way to describe my predicament in so few words. I am writing a communication framework...
Jon Skeet
people
quotationmark

You basically don't need to do anything except stop thinking about bytes as numbers. Think of them as 8 bits, and Java and C# are identical. It's rare that you really want to consider a byte as a magnitude - it's usually just binary data... more 10/11/2014 8:29:33 PM

people

Arrays of primitives in java vs C++

I wanted to know about differences in performance between arrays in c++ and java. I know that for object arrays in java, the objects are not stored contiguously in memory, only...
Jon Skeet
people
quotationmark

As far as I know the JVM doesn't guarantee that the array will be stored contiguously. While I don't see any cast-iron guarantee that the array elements will be stored contiguously, I believe they will for every mainstream... more 10/11/2014 7:54:27 AM

people