http://www.dotnetperls.com/extension
This program is given in the above website.
In this program directive using Extensions; is not used. Please tell what is the reason for that?
In my view return type and variable in question are same type that is why directive is not used. I wish to know whether my understanding is correct. Problem is highlighted.
using System;
public static class ExtensionMethods
{
public static string UppercaseFirstLetter(this string value)
{
//
// Uppercase the first letter in the string this extension is called on.
//
if (value.Length > 0)
{
char[] array = value.ToCharArray();
array[0] = char.ToUpper(array[0]);
return new string(array);
}
return value;
}
}
class Program
{
static void Main()
{
//
// Use the string extension method on this value.
//
string value = "dot net perls";
value = value.UppercaseFirstLetter(); // Called like an instance method.
Console.WriteLine(value);//Dot net perls
Console.ReadKey();
}
}
Loading


VulpesRank #55 · 29.2K reputationPosted Dec 17, 2014, 1:46 AM EST
However, if you'd placed the static class in a namespace called Extensions, then you would have needed the using directive to use the extension method from the global namespace:
Michal HabalcikRank #902 · 2.3K reputationPosted Dec 17, 2014, 1:44 AM EST
http://msdn.microsoft.com/en-us/library/bb383977.aspx
MahaRank #2,573 · 543 reputationPosted Dec 17, 2014, 2:02 AM EST
MahaRank #2,573 · 543 reputationPosted Dec 17, 2014, 4:19 AM EST
if (value.Length > 0)
{
char[] array = value.ToCharArray();
array[0] = char.ToUpper(array[0]);
return new string(array);
}
return value;
VulpesRank #55 · 29.2K reputationPosted Dec 17, 2014, 4:24 AM EST
MahaRank #2,573 · 543 reputationPosted Dec 17, 2014, 5:00 AM EST