Thursday 23 April 2020

Override ToString in Csharp

First question that comes to mind is why should I do that. My answer is “for fun”. ;)
The code is pretty simple to write. Here is a sample.

There are two return statements. One return name and salary, while the other returns json string.

It is mostly recommended to override ToString for debugging purposes.

I was able to find a good stackoverflow answer written in 2012, talks about why we should do that.

There is an important note on msdn article on how to override ToString which is as below.

"When you decide what information to provide through this method, consider whether your class or struct will ever be used by untrusted code. Be careful to ensure that you do not provide any information that could be exploited by malicious code."

You can find the complete program here.

1 comment:

  1. If you a glance at|have a look at} the entire Pareto graph you’ll find a smoother, longer tail in social. In playing, the participant plays to win and to get some type of a rush. If he wins huge, he'll normally cash out and may scale back his engagement 카지노 사이트 ranges in the close to future. In social gaming, there are many of|there are numerous} more features of social/fun engagement which encourage the participant. The participant needs to compete in the game, to go up in ranges, to beat his friends and to interact with them by sending presents. Our customer service may be very skilled phrases of|in relation to} international on-line casinos and they're in fact specialists in and every little thing our on line casino contains.