Browsing 7239 questions and answers with Jon Skeet

Why do I need to cast from ConcurrentDictionary to IDictionary in order to use Add()?

If I have a ConcurrentDictionary and want to use the Add() function, I need to cast to IDictionary: var cd = new ConcurrentDictionary<int, int>(); cd.Add(1, 1); // Compile...
Jon Skeet
people
quotationmark

My question: Why is ConcurrentDictionary implemented like that? I believe it's to encourage you to think of the concurrency implications - that multiple threads may be writing the same keys at the same time. Adding an existing key is... more 2/18/2014 8:15:28 AM

people

C# Singleton Pattern

I use the singleton pattern in a lot of places, sometimes the constructor does nothing, other times it's initialising things. I wondered if there was a way to set up an abstract...
Jon Skeet
people
quotationmark

I wondered if there was a way to set up an abstract class to minimise my code repetition a bit No, there isn't. As soon as you've got an abstract class, you've got a class which can be instantiated multiple times. I've seen various... more 2/18/2014 8:08:08 AM

people

Java Set, contains, false result

EventObject target = new EventObject("e2"); Set<EventObject> Following = o.getFollowingEvents(e1); System.out.println("Elements :...
Jon Skeet
people
quotationmark

It sounds like you've just forgotten to implement hashCode: @Override public int hashCode() { return getName().hashCode(); // Consistent with equals } Note that you don't really need to perform an ordering comparison in your equals... more 2/17/2014 4:15:15 PM

people

Java scentific date hanlding

My question is how should a Date be handled when we want to store dates since the birth of earth until end of earth (expected to be at 100000000000000000000-12-31 23:59:00.0000 +1...
Jon Skeet
people
quotationmark

JSR-310 - the new date/time API in Java 8 - handles this already. From the Instant docs: For practicality, the instant is stored with some constraints. The measurable time-line is restricted to the number of seconds that can be held in... more 2/17/2014 12:48:50 PM

people

What is the behavior when throwing an exception without setting out parameter?

What is the defined behaviour in C# for when an exception is thrown before setting the value of an out parameter, and you then try to access the parameter? public void...
Jon Skeet
people
quotationmark

What is the defined behaviour in C# for when an exception is thrown before setting the value of an out parameter, and you then try to access the parameter? You can't do so. The variable will still not be definitely assigned, unless... more 2/17/2014 9:49:47 AM

people

how to take the part of a string

how i can take a part of this string : string="<ArrayOfArrayOfKeyValueOfstringstring xmlns:d1p1="http://www.w3.org/2001/XMLSchema" i:type="d1p1:base64Binary"...
Jon Skeet
people
quotationmark

I'd use an XML API: XElement element = XElement.Parse(text); string value = element.Value; byte[] bytes = Convert.FromBase64String(value); more 2/17/2014 9:47:06 AM

people

put LINQ code in sitecore code

I would to get "comment" by article ID . and i only can to get all comment in all article. my plan is make LINQ code in my code please check my code var childrenss = new...
Jon Skeet
people
quotationmark

Well it looks like you should be able to use: using System.Linq; ... var children = item.GetChildren().ToList(); more 2/17/2014 8:35:16 AM

people

How to convert date to mysql date format

Table1 id int pk searchdate datetime amount float Data for Table1 id searchdate amount 1 2014-02-05 100 2 2014-02-02 245 3 2014-02-11 ...
Jon Skeet
people
quotationmark

Don't use string conversions at all. Use a PreparedStatement, and the setTimestamp method. // TODO: Cleanup etc PreparedStatement st = conn.prepareStatement( "select * from table1 where searchdate >= ? and searchdate <... more 2/16/2014 3:48:04 PM

people

How can I change the apparent type to a real type in Java?

for example : public static String s(Object o) return o; this method doesn't work/compile. To solve it I can write return o.toString() but I don't want that. I want to...
Jon Skeet
people
quotationmark

It sounds like you're just after a cast: public static String castToString(Object o) { return (String) o; } This will throw a ClassCastException if o is a non-null reference to a non-String type. (If o is a null reference, the cast... more 2/16/2014 3:29:12 PM

people

Java Tcp Server and .Net Tcp Client Problems with sending and receiving

i plan to write a Java TCP Server and a Client in C# .NET. I take Java for the Server because i have the ability to run the Server on Linux. My Problem is that the .NET Client can...
Jon Skeet
people
quotationmark

Your client sends the bytes of a line, and waits for a response, keeping the stream open. Your server waits for a line break (or the end of the stream, i.e. the connection being closed) before ReadLine returns. So both sides are waiting... more 2/16/2014 1:02:58 PM

people