tostring

How to change NaN string representation in C#?

北城以北 提交于 2019-12-04 03:08:58
问题 My program saves a pointcloud to file, where each pointcloud is a Point3D[,] , from the System.Windows.Media.Media3D namespace. This shows a line of the output file (in portuguese): -112,644088741971;71,796623005014;NaN (Não é um número) while I'd like it to be (on order to be correctly parsed afterwards): -112,644088741971;71,796623005014;NaN The block of code that generates the file is here: var lines = new List<string>(); for (int rows = 0; rows < malha.GetLength(0); rows++) { for (int

Since Int32 is a value type why does it inherit .ToString()?

*爱你&永不变心* 提交于 2019-12-04 02:10:13
These are the docs about .ToString() that has prompted this question. They state: Because Object is the base class of all reference types in the .NET Framework, this behavior [.ToString()] is inherited by reference types that do not override the ToString method. Yet further on it goes to state: For example, the base types such as Char, Int32, and String provide ToString implementations However Int32 is a struct and hence must be a value type . So what's going on here? Does Int32 implement it's very own .ToString() which has nothing to do with Object? Int32 is a struct and therefore a value

Why does Boolean primitive not call prototype toString()?

寵の児 提交于 2019-12-04 02:03:38
Say I have this code: Boolean.prototype.toString = function toString() { return this.valueOf() ? '1' : '0'; }; var object = { true: 'true', false: 'false', 1: '1', 0: '0' }; // "true" - this doesn't work console.log('primitive', object[true]); // "1" - but these do console.log('primitive.toString()', object[true.toString()]); console.log('instance', object[new Boolean(true)]); Why doesn't the primitive use the class's toString definition? Object keys are either strings or symbols, they cannot just be raw booleans. This is why I'm confused. Because the specifications says so. http://www.ecma

String.Format vs ToString()

女生的网名这么多〃 提交于 2019-12-03 23:53:55
Can anyone explain if there is any benefit in either one of the following methods: decimal d = 12.0m; // 1. how I'd have done it myLabel.Text = d.ToString(); // 2. how I saw someone do it today myLabel.Text = String.Format("{0}", d); Just to clarify, I'm not querying what the methods do, I'm obviously happy with that, just if there is perhaps a performance benefit in one over the other in this specific example. I'm aware of the added flexibility of cultures and formatting offered by string.format(), but I'd always just 'tostring()' numerics to attach their value to a label, or text based

ToString on null string

风流意气都作罢 提交于 2019-12-03 23:34:14
Why does the second one of these produce an exception while the first one doesn't? string s = null; MessageBox.Show(s); MessageBox.Show(s.ToString()); Updated - the exception I can understand, the puzzling bit (to me) is why the first part doesn't show an exception. This isn't anything to do with the Messagebox, as illustrated below. Eg : string s = null, msg; msg = "Message is " + s; //no error msg = "Message is " + s.ToString(); //error The first part appears to be implicitly converting a null to a blank string. because you cannot call instance method ToString() on a null reference. And

Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

拜拜、爱过 提交于 2019-12-03 22:43:11
I see that, in C#, rounding a decimal , by default, uses MidpointRounding.ToEven . This is expected, and is what the C# spec dictates. However, given the following: A decimal dVal A format string sFmt that, when passed in to dVal.ToString(sFmt) , will result in a string containing a rounded version of dVal ...it is apparent that decimal.ToString(string) returns a value rounded using MidpointRounding.AwayFromZero . This would appear to be a direct contradiction of the C# spec. My question is this: is there a good reason this is the case? Or is this just an inconsistency in the language? Below,

Type overloading macro

末鹿安然 提交于 2019-12-03 13:57:45
I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe typeof but apparently that doesn't work. example macro(I also have some ascii terminal color stuff that I can't remember of the top of my head) #ifdef _DEBUG #define DPRINT_INT(x) printf("int %s is equal to %i at line %i",#x,x,__LINE__); . . . #else #define DPRINT_INT(x) . . . #endif Try this; it uses gcc's __builtin methods, and automatically

Object.prototype.toString()

六月ゝ 毕业季﹏ 提交于 2019-12-03 12:45:06
语法: obj.toString() 返回值: 一个表示该对象的字符串 描述: 每个对象都有一个toString()方法,当该对象被表示为一个文本值时,或者一个对象以预期的字符串方式引用时自动调用。默认情况下,toString() 方法被每个Object对象集成,如果此方法再自定义对象中未被覆盖,toString()返回“[object type ]”,其中type是对象的类型。举例 var o = new Object(); o.toString() //[object Object] 使用 toString() 检测对象类型: 可以通过 toString() 来获取每个对象的类型。 为了每个对象都能通过 Object.prototype.toString() 来检测,需要以 Function.prototype.call() 或者 Function.prototype.apply()的形式来调用传递要检查的对象作为第一个参数,称为 thisArg var toString = Object.prototype.toString; toString.call(new Date); // [object Date] toString.call(new String); // [object String] toString.call(Math); // [object Math]

Converting Range or DocumentFragment to string

我只是一个虾纸丫 提交于 2019-12-03 10:51:11
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 DocumentFragments have no innerHTML property (at least in Firefox; have not tried Webkit or Opera). Which seems odd to

toString Method Call in Java [duplicate]

我的未来我决定 提交于 2019-12-03 10:16:01
This question already has answers here : Why is the toString() method being called when I print an object? (5 answers) Possible Duplicate: Why is the toString() method being called when I print an object? I have this piece of code below. I understand everything else except the output using the toString method in the Room Class . In the HotelMain Class, I just called the displayRooms Method that was in the Hotel Class . But, when I ran the program, the toString output was shown in the console. If I'm right toString() is the textual representation of the value in the object. But, I'm not sure