tostring

Why typeof(int).ToString() is not constant?

血红的双手。 提交于 2019-12-12 17:09:27
问题 I'm trying to do this: const string intType = typeof(int).ToString(); switch (typeof(MyT).ToString()) { case intType: { return "int"; break; } ... } But compiler says: error CS0133: The expression being assigned to 'intType' must be constant As I know, typeof operator works at compile-time. So, what's wrong? 回答1: As I know, typeof operator works at compile-time. You don't know that because knowledge has to be true . Where did you get the idea that typeof is executed at compile time? It

The DateTime.Parse is off by one hour. Why?

こ雲淡風輕ζ 提交于 2019-12-12 16:03:42
问题 I've been having some trouble understanding why the value of a restored date time string differs from its original. I'm writing the string to universal datetime (format "u" so it has a 'z' at the end), but when it is restored, it differs by one hour. I'm using the "u" to prevent this kind of stuff from happening. Can anybody tell me why it differs? I need a good string representation, because I'll use the code in 5 different time-zones. The program: using System; namespace ConsoleApplication1

C# creating a custom NumberFormatInfo to display “Free” when a currency value is $0.00

∥☆過路亽.° 提交于 2019-12-12 12:03:08
问题 I need to display a currency in my ASP.NET MVC application but when the currency is 0 I would like it to display "Free" (localized of course!) instead of $0.00. So when I have something like this... Decimal priceFree = 0.00; Decimal priceNotFree = 100.00; priceFree.ToString("C"); priceNotFree.ToString("C"); The output is "$0.00" "$100.00" I would like it to be "Free" "$100.00" I imagine I can use the .ToString(string format, IFormatProvider formatProvider) method to accomplish this but I'm

Why does Chrome produce 1099 digits after the dot for (.1).toString(3)?

别说谁变了你拦得住时间么 提交于 2019-12-12 11:16:45
问题 I have a feeling that this is a just a harmless bug but I'd still like to understand what's going on. I was playing with some code to render a Peano curve on a canvas that involves expressing logical coordinates in base 3 when I noticed that a function was returning absurdly long strings in Chrome. Looking more closely, it turns out that the expression (.1).toString(3) evaluates in Chrome to 0

JavaScript using toString on a Function object to read text content

不打扰是莪最后的温柔 提交于 2019-12-12 10:55:52
问题 Calling toString() on the function below returns different strings across browsers. I understand this is because ECMA-262 15.3.4.2 leaves wiggle room for each vendor. Chrome returns the comments in addition to all syntax. Sadly Firefox 3.6 omits the comments. Based on Firefox's behavior I haven't tested IE, Opera, or Safari. function foo() { /* comment */ var bar = true; } Specifically, I am attempting to embed meta data within a specially formatted comment block within a function. Later the

Converting Range or DocumentFragment to string

不打扰是莪最后的温柔 提交于 2019-12-12 07:44:53
问题 Is there a way to get the html string of a JavaScript Range Object in W3C compliant browsers? For example, let us say the user selects the following: Hello <b>World</b> It is possible to get "Hello World" as a string using the Range.toString() method. (In Firefox, it is also possible using the document 's getSelection method.) But I can't seem to find a way to get the inner HTML. After some searching, I've found that the range can be converted to a DocumentFragment Object. But

How do I convert a StringReader to a String?

﹥>﹥吖頭↗ 提交于 2019-12-12 07:13:02
问题 I'm trying to convert my StringReader back to a regular String , as shown: String string = reader.toString(); But when I try to read this string out, like this: System.out.println("string: "+string); All I get is a pointer value, like this: java.io.StringReader@2c552c55 Am I doing something wrong in reading the string back? 回答1: The StringReader 's toString method does not return the StringReader internal buffers. You'll need to read from the StringReader to get this. I recommend using the

Problems using the toString method in Java [closed]

余生长醉 提交于 2019-12-12 04:05:16
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm working on a banking program that is supposed to use 3 classes (Account-base class, CheckingAccount, and SavingsAccount) and several methods to display the banking information (ID, balance after a withdrawal and deposit, and the annual interest rate). This should be a pretty simple program, but I'm getting

Check if Property is List using Reflection in C#

老子叫甜甜 提交于 2019-12-11 23:36:45
问题 I'm stuck at putting out the values of my objects at the moment. Some of them do have List<string> properties which causes trouble by using the ToString() Method. Here is the code I use in my base class to get the name and the value of the properties into a string. public override string ToString() { string content = ""; foreach (var prop in this.GetType().GetProperties()) { if (prop.PropertyType is IList<string> && prop.GetType().IsGenericType && prop.GetType().GetGenericTypeDefinition()