Can you add extension methods...
Can you add extension methods...
Yes, you can add extension methods to an existing static class in C#. Here's how:
this
keyword before the first parameter of the extension method, specifying the type you want to extend.Here's an example:
public static class StringExtensions
{
public static string Reverse(this string str)
{
return new string(str.Reverse().ToArray());
}
}
In this example:
StringExtensions
.Reverse
that takes a string
as its first parameter, preceded by the this
keyword.expert
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào