7
With C# 6 and interpolation usage is better than concatenating string with data.
As in the example.
Instead of:
var d = "19";
string.Format("{0} anos", d);
looks much better
$"{d} anos";
But using the feature, I created a column in my database which will be fed by the user through object.
I have an immovable object with its properties.
When performing direct interpolation as:
$"{imovel.Nome} aqui é meu imóvel";
Works perfectly.
But now I have this information "{imovel.Nome} aqui é meu imóvel"
in a column.
And through a foreach
I need it to work, someone has some idea of how to solve?
Ex:
var imovel = new Imovel().GetImovel(); // aqui retorna meu objeto imovel
foreach(var t in Textos){
var meuTexto = $""+ t; // aqui tem isso "{imovel.Nome} aqui é meu imóvel"
var TextoInterpolado = meuTexto; // aqui deveria formatar Casa1 aqui é meu imóvel, mas ele mostra apenas assim "{imovel.Nome} aqui é meu imóvel"
}
I do not know if it was very clear, but I want something like this example: https://dotnetfiddle.net/Zk3nbL
The answer is simple: You can’t do it that way. But it can be done this way
– Bruno Costa