Browsing 7239 questions and answers with Jon Skeet

Converting java code to c#

I am making a porting of this code from java(Android) to C#(Windows Phone) but i have no idea how to do that, here is the code that i'm trying do convert: private void...
Jon Skeet
people
quotationmark

There's no equivalent to anonymous inner classes in C#. For single-method versions, you can often use delegates instead of interfaces, then use lambda expressions (or just regular methods) to specify an implementation. Otherwise, just use... more 1/15/2015 4:18:57 PM

people

Parsing TimeSpan with optional minus sign

MSDN says: The styles parameter affects the interpretation of strings parsed using custom format strings. It determines whether input is interpreted as a negative time...
Jon Skeet
people
quotationmark

It looks like this isn't supported. From the custom TimeSpan format strings page: Custom TimeSpan format specifiers also do not include a sign symbol that enables you to differentiate between negative and positive time intervals. To... more 1/15/2015 2:30:57 PM

people

4 Backslash on network path string

If I do this: string path = "\\myServer\myFile.txt" I get a compilation error. So I do this: string path = @"\\myServer\myFile.txt" Altought the output of path in QUICK...
Jon Skeet
people
quotationmark

Although the output of path is: \\\\myServer\myFile.txt No, it's not. The value you might see in the debugger would be \\\\myServer\\myFile.txt which is just the debugger escaping the value for you. The value of the string has... more 1/15/2015 1:02:46 PM

people

Java File Operation Reading a file whose name we get from the user in console input

I have to get the name of a file, say, A.txt from user in console and open the file and read it(to be more specific, tokenize it). How can I do it? I am not able to get the...
Jon Skeet
people
quotationmark

args[0] will refer to the first command line argument, e.g. java Foo filename.txt If you want it on the interactive console, i.e. after the program has started, you should use System.in, e.g. BufferedReader reader = new... more 1/15/2015 7:06:37 AM

people

Is a DLL with only constants needed in distribution?

I've created two executable projects which depend on a single class library. The class library contains only classes and constants (no variables or functions), and is used to...
Jon Skeet
people
quotationmark

If they are genuine constants, introduced with const, then the value of each constant will be inlined where it's used. For example, if you have: // Assembly1 public static class Constants { public const string Foo = "Hello"; } //... more 1/14/2015 4:51:44 PM

people

What does using @NonNull on a void method do?

What's the point in Lombok annotation @NonNull for a method? class MyClass { @NonNull void run() { // code here } } Are we check the instance of class...
Jon Skeet
people
quotationmark

For a void method, there's no point. For a method with a return type, it shows that it won't return null: @NonNull String foo() { // I promise I won't return null herre! } Judging by the tutorial, it looks like it won't generate a... more 1/14/2015 4:39:00 PM

people

hashCode() for string returning negative value

"random".hashCode() returns a value -938285885. Are negative values expected for hashCode()? According to the following question, there's a way the hashCode() for string is...
Jon Skeet
people
quotationmark

Are negative values expected for hashCode()? They're entirely valid, yes. won't the value keep increasing as the length of string increase and eventually be greater than Integer.MAX_VALUE? What makes you think that hash codes... more 1/14/2015 4:19:22 PM

people

when we create an object ,do creation of object and the execution of constructor happens at the same time?

When we create an object, do creation of object and the execution of constructor happens at the same time or first object is created then constructor execution take place? Its...
Jon Skeet
people
quotationmark

Section 12.5 of the JLS gives the details. The bare bones of it is: Memory space is allocated (with all fields having the default value for the relevant type, e.g. null or 0) The specified class's constructor is called, which will... more 1/14/2015 4:08:57 PM

people

C# grammar "base"

I am looking into the grammar of C# 5.0 and don't quite understand the use of "base". In the reference manual, there is a notion of "base access" defined as: base-access: ...
Jon Skeet
people
quotationmark

I believe it should actually be base-access: base . identifier type-argument-list_opt base [ expression-list ] ... which would make it just like member-access: member-access: primary-expression . identifier ... more 1/14/2015 2:01:59 PM

people

Constructor with abstract class won't accept specific

I have an abstract class Animal with extended classes of Horse and Pig. I also have a Farm class and a constructor in that class which I want to use to populate a list of what...
Jon Skeet
people
quotationmark

The idea is that it will add multiple animals of whatever type I pass in to the farmlist. In that case you need to pass in the type of an Animal - not a reference to an instance of an Animal, which is what you're doing at the moment.... more 1/14/2015 12:01:52 PM

people