Browsing 7239 questions and answers with Jon Skeet

Why does decimal min value not convert to a string?

The following console app crashes: decimal dec = decimal.MinValue; string str = string.Format("{0:d}", dec); Console.WriteLine(str); The error is: Format specifier was...
Jon Skeet
people
quotationmark

From the documentation: This format is supported only for integral types. decimal isn't an integral type. The fact that the format type is called "decimal" is unfortunate, basically. It's because it formats integers in base 10, but... more 3/24/2014 10:30:34 AM

people

Error about local variable in Entity Framework

ERROR Message: A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope...
Jon Skeet
people
quotationmark

You've already got a method parameter called e, so you can't introduce a lambda expression parameter called e. You'll need to rename one of them. As a shorter example, to show this has nothing to do with EF etc: // Invalid: same variable... more 3/24/2014 7:40:34 AM

people

how to add element with multiple attribute to a specific node

here is my XML doc <Filters> <Filter Name="ddd"> <File Name="filename.xls" Location="\\path\filename.xls"> <Sheet Name="'sheetname'"> ...
Jon Skeet
people
quotationmark

Well yes, you're calling xml.Add when you actually want to call Add on the object representing the Sheet element. I suggest you use: XElement sheet = new XElement("Sheet", new XAttribute("Name", getExcelSheetName); while... more 3/24/2014 7:02:42 AM

people

Port in IPAddress

I get a string ,representing ip address .It has format ip:port I need to generate IPAddress .Will use for that : public static IPAddress Parse( string ipString ) The...
Jon Skeet
people
quotationmark

Assuming there's there's always a port and it's always represented by :<port number>, you can just unconditionally remove the part after the last colon: int portStart = ipString.LastIndexOf(':'); ipString = ipString.Substring(0,... more 3/23/2014 8:28:52 AM

people

is it possible to make a method run continuously until I input a special character

I have the code below, my question is : is it possible to make a method run continuously until I input a special character public static int remainder (int dividend, int...
Jon Skeet
people
quotationmark

It sounds to me like you need to think about your structure differently. The remainder method probably shouldn't interact with the console - you need to loop in the code calling it: // Calling code, e.g. main Console console =... more 3/23/2014 8:22:08 AM

people

error CS1012: Too many characters in character literal why it sometimes compile and sometimes not

I have this code: this.lentry2.InvisibleChar = '●'; it compiles perfectly everywhere, except for ubuntu's launchpad. When I am building this in there I am receiving this CS1012...
Jon Skeet
people
quotationmark

I suspect it's all to do with the character encoding the compiler is using to convert your file into text. You can specify this in the mcs command line with the -codepage parameter. (Or /codepage in csc.) Alternatively, to make it easier... more 3/22/2014 7:06:26 PM

people

Instance variable hiding with inheritance

In the code below, the instance variable called "x" inside subclass "B" hides the instance variable also called "x" inside the parent superclass "A". public class A { public...
Jon Skeet
people
quotationmark

In the code below, why does println(z.x) display the value of zero? Because it's referring to the z field declared in A... that's the only one that z.x can refer to, because the compile-time type of z is A. The instance of B you've... more 3/22/2014 5:36:58 PM

people

GetBytes() returns negative number

*"Hätten Hüte ein ä im Namen, wären sie möglicherweise keine Hüte mehr, sondern Häte." 72 -61 -92 116 116 101 ...* GetBytes() returns negative number (-61, () ) at the...
Jon Skeet
people
quotationmark

GetBytes() returns negative number (-61, () ) at the char 'ä'. Well getBytes() is going to use the platform default encoding, unless you specify an encoding, which you should. I would recommend UTF-8 normally. For example, in Java... more 3/22/2014 8:39:24 AM

people

From timestamp to date in Java

I've a problem creating new date in Java. I receive from webservice a timestamp (for example 1397692800). You can see from this online converter that is equal to 17 Apr 2014. When...
Jon Skeet
people
quotationmark

The Date(long) constructor takes the number of milliseconds since the Unix epoch. I strongly suspect that you've been given the number of seconds since the Unix epoch - so just multiply that value by 1000L. Date date = new Date(timestamp... more 3/22/2014 8:36:51 AM

people

In Java, how do I check if a string begins and ends the same way?

I'm learning Java, and I'm completing some problems tasked to me. I've come across a specific problem and I feel like the answer is so simple, but I just can't find it. I need...
Jon Skeet
people
quotationmark

You're calling startsWith when you don't need to - you know it starts with the first two characters, by definition :) You could have: String start = text.substring(0, 2); boolean valid = text.endsWith(start); Or just collapse the... more 3/22/2014 8:24:49 AM

people