Hi,
After 12 hours of Visual Studio from last Tuesday, I grabbed me a virus that almost killed me. But little by little I will remove the earrings, we start by some emails.
Good, I was the other day watching with my coworkers 12 hours of Visual Studio, and part of seem very interesting items that you enseñasteis, we are left with the question of how to make a “trick” that we found to be quite useful in day to day… how to convert a string of the type “Hello” + < variable > + “que tal” in the string.Format(“hola_{0}_que_tal”,<variable>) automatically. We see you do it in the talk, but we do not know how, hehe.
Therefore, that becomes so well live and also much better in the code is thanks to ReSharper. To show an example, I have a console application with the following code:
1: using System;
2: namespace ConsoleApplication2
3: {
4: class Program
5: {
6: static void Main(string[] args)
7: {
8: const string Name = @"Valentino";
9: var msg = "Hola mi nombre es " + Name;
10: Console.WriteLine(msg);
11: }
12: }
13: }
If we are positioned on line 9, we see that ReSharper offers us the possibility of using format string for concatenation of strings.
After selecting this option, we have no more a sum of strings
But this is not all, the second option offered to us by ReSharper is also interesting, “Compute constant value”. In the same R # identifies that we are working with a constant and offers us the possibility of using the same value instead of working with a chain. The end result would be as follows:
1: using System;
2: namespace ConsoleApplication2
3: {
4: class Program
5: {
6: static void Main(string[] args)
7: {
8: const string Name = @"Valentino";
9: var msg = string.Format("Hola mi nombre es {0}", Name);
10: Console.WriteLine(msg);
11: }
12: }
13: }
1: using System;
2: namespace ConsoleApplication2
3: {
4: class Program
5: {
6: static void Main(string[] args)
7: {
8: const string Name = @"Valentino";
9: var msg = "Hola mi nombre es Valentino";
10: Console.WriteLine(msg);
11: }
12: }
13: }
Obviously, if we change the value of the constant we are more fried than the Chicago Bulls without Derrick Rose, but that topic for another post.
Greetings @ Home
El Bruno


Leave a comment