Browsing 7239 questions and answers with Jon Skeet

does package need to be in jar for ant build script

does a java package need to be packaged into a jar for ANT to see it on the classpath or can it just be a regular folder structure/directory with .class files?
Jon Skeet
people
quotationmark

You can just leave the class files in file system directories - but as normal, that directory hierarchy should match the package structure of the classes. Basically, an Ant classpath is just like a classpath in a normal Java tool - just... more 7/15/2014 4:14:02 PM

people

Linq Expression property type

I have a linq expression defined as follows: private void GetMyPropertyType<T>(Expression<Func<T, object>> expression) { // some code ----- HERE...
Jon Skeet
people
quotationmark

You can use Expression.Type to find out the static type of the expression. However, because you've got Expression<Func<T, object>> you've actually got a conversion expression around the property expression, so you need to... more 7/15/2014 12:32:32 PM

people

Make the current point of a C# stream the beginning

I have to read some bytes of a C# stream and then pass the stream to a library method, which should read the rest of it. Unfortunately, this method calls a stream.Seek(0,...
Jon Skeet
people
quotationmark

No, there's nothing that does that... but what you could do is create your own wrapper stream which maintains a reference to the original stream, and delegates all calls to it... modifying any Seek() or Position calls appropriately. You... more 7/15/2014 8:34:01 AM

people

what does obj1 == obj2 actually compare

I am studying Overriding hashCode() and equals(Object obj) methods of Object class. body of equals(Object obj) method in Object class is : public boolean equals(Object obj) { ...
Jon Skeet
people
quotationmark

How does it know that the variables refer to the same object? Because the values of the variables are the same references. (Your variables are t1 and t2. The values of those variables are references. Those references are used as a way... more 7/15/2014 8:01:31 AM

people

Increment value from expression

I want to write a closure and increment it's value but i'm not able to do it. Here is my code int i = 0; Expression<Func<bool>> closurExpression = ()...
Jon Skeet
people
quotationmark

Well, you can do sidestep the rules using Interlocked.Increment: int i = 0; Expression<Func<bool>> expression = () => Interlocked.Increment(ref i) != 0; ... but I would be very cautious about doing so. I wouldn't expect... more 7/14/2014 6:16:34 PM

people

C# can't compare two datetimes properly

I'm new to C# and I'm trying to write a simple console application. I have two datetimes but I can't get the message Same, It keeps printing Different. I also print the two...
Jon Skeet
people
quotationmark

DateTime has a resolution down to ticks, even though by default they're only printed to seconds in most cultures. If you print dt1.ToString("o") and the same for dt2, you'll see that even if they're equal to the second, they may well vary... more 7/14/2014 5:45:42 PM

people

Is it possible to have class members of an anonymous class?

I'm trying to create a class that has fields in it that are of an anonymous type. (This is for Json deserialization.) I can't find a syntax that the compiler will accept. I'm...
Jon Skeet
people
quotationmark

You can declare a field using an anonymous type initializer... you can't use implicit typing (var). So this works: using System; class Test { static object x = new { Name = "jon" }; public static void Main(string[] args) { ... more 7/14/2014 5:44:09 PM

people

How does strings’ immutability help in string interning?

An answer to this question mentions that the immutable characteristic of string helps in achieving string interning. Can anyone please explain how the characteristic of being...
Jon Skeet
people
quotationmark

If String were a mutable type, it simply couldn't be interned. There's no point in keeping a pool of objects if they can be mutated... you wouldn't be able to rely on what you got out of the pool being the string you were interested in (at... more 7/14/2014 5:35:08 PM

people

How to select something within an XML attribute?

I am currently attempting to replace a certain string in an xml document. I am doing this through Visual Studio using C#. The exact string I want to replace is Data Source =...
Jon Skeet
people
quotationmark

This has really nothing to do with XML - the fact that the value of the attribute is itself a semi-colon-separated list is irrelevant as far as XML is concerned. You'd have the same problem if you had the connection string on its own. You... more 7/14/2014 3:24:15 PM

people

how to access to end element of a map?

I have this method: public String nodePropertyGenerator(Map<String,Object> properties){ String prop=""; for(Map.Entry<String, Object> entry :...
Jon Skeet
people
quotationmark

You can't tell whether the current iteration is the last one. I suggest you use a StringBuilder instead of repeated string concatenation, then just trim the length at the end: StringBuilder builder = new StringBuilder(); for... more 7/14/2014 12:07:23 PM

people