1
I’m trying to create a Extension Methods
for the class string
. He’s not showing up.
My class with the extension method:
namespace MEUPROJETO.Extension
{
public static class StringExtension
{
public static string PrimeiraLetraDeCadaPalavraMiuscula(this string frase)
{
frase = frase.ToLower();
System.Globalization.CultureInfo cultureinfo = System.Threading.Thread.CurrentThread.CurrentCulture;
return cultureinfo.TextInfo.ToTitleCase(frase);
}
}
}
Class where I try to use it:
namespace MEUPROJETO.Teste
{
public static class TesteExt
{
public static void teste( )
{
string catdescription = "TESTANDO a frase nessa STRING.";
catdescription = catdescription.PrimeiraLetraDeCadaPalavraMiuscula();
}
}
}
He can’t even compile, says the method doesn’t exist, like I do for him to appear?
The namespace influences?
You must specify the namespace where the Extension Method is declared:
using MEUPROJETO.Extension
– ramaral
Thank you! Put as answer I mark you!
– Ricardo