いつもお世話になっております。
以下のような拡張メソッドを作成し、
csharp
1using System; 2 3namespace CustomExtensions 4{ 5 public static class StringExtension 6 { 7 public static int WordCount( this String str ) 8 { 9 return 0; 10 } 11 } 12}
拡張メソッドを作成したクラスとは別の名前空間の関数から呼び出す際は、usingを使用すれば呼び出せると思います。
csharp
1using System; 2 3namespace ProjectA 4{ 5 using CustomExtensions; 6 7 class Program 8 { 9 static void Main( string[] args ) 10 { 11 string s = "The quick brown fox jumped over the lazy dog."; 12 int i = s.WordCount(); 13 } 14 } 15}
この際usingを使用せずに、CustomExtensionsの名前空間を指定して拡張メソッドを呼ぶことは出来ないでしょうか。
csharp
1using System; 2 3namespace ProjectA 4{ 5 // usingを出来ることなら使用したくないです。 6 // using CustomExtensions; 7 8 class Program 9 { 10 static void Main( string[] args ) 11 { 12 string s = "The quick brown fox jumped over the lazy dog."; 13 14 // CustomExtensionsの名前空間を指定してWordCount()を呼び出したいです。 15 int i = s.WordCount(); 16 } 17 } 18}
ご存知でしたらご教授をお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/22 09:38
2016/07/22 10:50
2016/07/22 10:58
2016/07/23 07:35