Can you add extension methods to an existing static class?
Can you add extension methods to an existing static class?
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.Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.