tostring

c# toString() performance

喜你入骨 提交于 2019-12-08 17:19:04
问题 I'm curious about the ToString() method in C#. Take for example the following: object height = 10; string heightStr = height.ToString(); When I call ToString() on height , I get a string type back. Is the runtime allocating memory for this string? 回答1: Yes, the runtime is going to allocate memory for any string object that you create or request, including one that is returned from a method call. But no, this is absolutely not something that you have to worry about. It will not have any

Equivalent of Java's toString() for Clojure functions

你。 提交于 2019-12-08 15:58:56
问题 some Java code I'm using invokes toString() on my Clojure function objects, which return something like #<ns$something something.something$something@7ce1eae7>> - I want to return something else...presumably there's a way to include some metadata in the functions so their objects' toString() returns that instead ? 回答1: If you just want to make the REPL print-out of your objects more meaningful, you can implement a defmethod print-method for the class in question. Here's a shortened version of

Is overriding std::to_string for user defined enums the proper way to provide to_string for user defined enums?

删除回忆录丶 提交于 2019-12-08 14:42:00
问题 C++ doesn't have a way to get the string representation of an enum. People get around this by writing custom functions that contain a lot of boilerplate code aka switch with case XYZ return "XYZ"; That of course requires users of the enum to know the name of the custom function. So I thought I could just add a specialization to std::to_string to enable a user to use to_string on my enums. Something like this: // #include <iostream> #include <string> #include <cassert> #define TEST class Car {

How to write an extension method for DataTable.Rows[i][j]? [closed]

余生长醉 提交于 2019-12-08 12:56:32
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I would like to create an extension method to be implemented like below (if it is even possible) which would be similar to the .ToString() extension method. Can someone please point me in the right direction. I attempted to search it in Google and cannot locate anything. DataTable table = db

重载toString产生的无限递归

蹲街弑〆低调 提交于 2019-12-08 09:25:10
class InfiniteRecursion { @Override public String toString () { return "SXD" + this ; } } 字符串’SXD’碰到加号会试图把后面的this也转化成String,于是调用this.toString()进入死循环,抛出java.lang.StackOverflowError异常, Java编程思想(P510)采用调用父类的方法super.toString() 来源: CSDN 作者: CodingBugs 链接: https://blog.csdn.net/qq_33061377/article/details/79249942

AS3: Can ByteArray return its content as a string with two bytes per unicode character?

偶尔善良 提交于 2019-12-08 06:07:02
问题 var bytes:ByteArray = new ByteArray; bytes.writeInt(0); trace(bytes.length); // prints 4 trace(bytes.toString().length); // prints 4 When I run the above code the output suggests that every character in the string returned by toString contains one byte from the ByteArray. This is of course great if you want to display the content of the ByteArray, but not so great if you want to send its content encoded in a string and the size of the string matters. Is it possible to get a string from the

Forcing Java 8 LocalTime toString to report omitted values

China☆狼群 提交于 2019-12-08 05:36:22
问题 I have the following datetime helper method that converts a UTC-zoned Java 8 Date into a datetime string: public static String dateTimeString(Date date) { return date.toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime().toString(); } The desired result is to always have the resultant String be formatted as: YYYY-MM-dd'T'HH:mm:ss'Z' Problem is, Java 8 LocalTime#toString() intentionally strips off time components that are zero. So for instance if I have a Date instance that represents June 8,

c# double to character array or alternative

不羁岁月 提交于 2019-12-07 17:15:53
问题 I have a program which stores a bunch of structs instances containing many members of type double. Every so often i dump these to a file, which I was doing using string builder e.g. : StringBuilder builder = new StringBuilder(256); builder.AppendFormat("{0};{1};{2};", x.A.ToString(), x.B.ToString(), x.C.ToString()); where 'x' is an instance of my type, and A,B,C are members of X of type double. I call ToString() on each of these to avoid boxing. However, these calls to ToString still allocate

ToString() returns null?

倖福魔咒の 提交于 2019-12-07 16:53:56
问题 I am trying to determine cause of 'Null reference exception' on published remote site. So, I can't debug it directly and can operate only with logs. So my question is: Is it possible, that .ToString() method of any of built-in .NET types returns null ? EDIT: I suspect DateTime.ToString(invariantCulture) method with badly constructed culture settings. 回答1: I don't know of any types where it does. It's not impossible - it would certainly be easy to write your own type which behaved like that -

Lombok主要常用的注解

依然范特西╮ 提交于 2019-12-07 16:16:29
Lombok 主要常用的注解有: @Data,@getter,@setter,@NoArgsConstructor,@AllArgsConstructor,@ToString,@EqualsAndHashCode,@Slf4j,@Log4j 。我们一个一个来看: @Data 注解: 在 JavaBean 或类 JavaBean 中使用,这个注解包含范围最广,它包含 getter 、 setter 、 NoArgsConstructor 注解,即当使用当前注解时,会自动生成包含的所有方法; @getter 注解: 在 JavaBean 或类 JavaBean 中使用,使用此注解会生成对应的 getter 方法; @setter 注解: 在 JavaBean 或类 JavaBean 中使用,使用此注解会生成对应的 setter 方法; @NoArgsConstructor 注解: 在 JavaBean 或类 JavaBean 中使用,使用此注解会生成对应的无参构造方法; @AllArgsConstructor 注解: 在 JavaBean 或类 JavaBean 中使用,使用此注解会生成对应的有参构造方法; @ToString 注解: 在 JavaBean 或类 JavaBean 中使用,使用此注解会自动重写对应的 toStirng 方法; @EqualsAndHashCode 注解: