Browsing 7239 questions and answers with Jon Skeet

How to make thread safe singleton class which can accepts parameter?

I am trying to make a class as ThreadSafe Singleton but somehow I am not able to understand how to make ThreadSafe Singleton class which can accepts parameter. Below is the class...
Jon Skeet
people
quotationmark

A singleton which requires a parameter is a bit of a contradiction in terms. After all, you'd need to supply the parameter value on every call, and then consider what would happen if the value was different to an earlier one. I would... more 2/13/2014 11:05:06 PM

people

Illegal escape character netbeans

I have a programming assignment which requires the code to be single line(shortest code). I did it, but for some reason, I get the error "Illegal Escape Character". Some people...
Jon Skeet
people
quotationmark

This, this is the problem: matches(".*@.*\..*") I suspect you want a regular expression with exactly this pattern: .*@.*\..* But you're writing it as a Java string literal, so you need to escape the backslash: matches(".*@.*\\..*")... more 2/13/2014 7:51:22 PM

people

Joda Time String to DateTime conversion

I require some help converting the following Thu, 13 Feb 2014 16:43:58 +0000 string to type DateTime. I have a stream of tweets being stored in an ElasticSearch cluster, currently...
Jon Skeet
people
quotationmark

You only want a single Z to represent "offset without a colon". Also note that you should ensure that your DateTimeFormatter is using English month/day names. For example: import java.util.*; import... more 2/13/2014 6:34:40 PM

people

Why must I use keyword static when they don't have to?

I've been trying simple experiments to learn C# methods. The below code simply calls playerSelection() which asks the user for a character and returns that character to...
Jon Skeet
people
quotationmark

In their example, they're creating an instance of Program, and calling a method on that instance: (new Program()).run(); This is more cleanly written as: Program program = new Program(); program.run(); From within those instance... more 2/13/2014 5:56:55 PM

people

combine foreach loop and linq query into single linq query

I have summarized my problem in following c# code snippet.In which I am filtering hotel by review.we get user review from user in the from of comma separated value.Currently I am...
Jon Skeet
people
quotationmark

It sounds like you've got a join, basically: var ratings = filterHotel.Split(',').Select(text => int.Parse(text)).Distinct(); var list = DAL.Get() .Join(ratings, hotel => hotel.Review, rating => rating, ... more 2/13/2014 4:57:07 PM

people

Getting Arizona time with getTime()

date= Calendar.getInstance(); Date currentDate = date.getTime(); String sDate = currentDate.toString(); This returns time EST. I need to change it to Arizona time which is...
Jon Skeet
people
quotationmark

This returns time EST. Well, Date.toString() will, if you're in EST at the moment. It's not part of the data stored within the Date - that's just an instant in time, with no idea what time zone or calendar system it might have started... more 2/13/2014 4:19:23 PM

people

C# Syntax lambdas with curly braces

delegate int AddDelegate(int a, int b); AddDelegate ad = (a,b) => a+b; AddDelegate ad = (a, b) => { return a + b; }; The two above versions of AddDelegate are...
Jon Skeet
people
quotationmark

A statement lambda contains a block of statements... which means you need a statement terminator for each statement. Note that this is similar to anonymous methods from C# 2: AddDelegate ad = delegate(int a, int b) { return a + b;... more 2/13/2014 4:09:36 PM

people

Preserve comments when Overriding

Is there a way (tool, or something) that permits do not duplicate the same XML comments when inheriting/Overriding methods from the base classes? Eg.: /// <summary> ///...
Jon Skeet
people
quotationmark

I think you're looking for inheritdoc: /// <inheritdoc /> public override bool Equals(object obj) This is not a standard tag (so Intellisense may not support it, for exampple), but it's pretty commonly used - in particular,... more 2/13/2014 3:56:20 PM

people

What is the difference between the method writeChar and writeShort in java.io.DataOutputStream class?

I am currently learning basic I/O of java. Please see the following code: import java.io.DataOutputStream; import java.io.IOException; public class TestIO { public static void...
Jon Skeet
people
quotationmark

However, what is the difference between the two methods if they both simply write two bytes to the outputstream? This sounds trite, but: one takes a char, the other takes a short. Those types aren't convertible to each other, and you... more 2/13/2014 3:04:37 PM

people

Querying Utf 8 with C# by Using Prepared Statement

Sorry if this question is duplicate and also very simple question. However I can't solve my query problem. I'm new to C# queries. I need to do query like " select * from table...
Jon Skeet
people
quotationmark

The N part is a prefix for a literal. You shouldn't need to to that. I would expect this to work: commandString = "select * from table where att=@param"; command.Parameters.Add("@param", SqlDbType.NVarChar).Value = "ğasd"; Note the... more 2/13/2014 2:42:00 PM

people