【发布时间】:2009-04-28 02:48:52
【问题描述】:
重复大约 20 个最近的问题;有人请链接他们。
对于简单的场景,我应该何时使用其中一种?有什么优缺点?
使用扩展方法有哪些建议?
编辑:
让我举个例子。假设我有一个表示为字符串的 Web 相对路径。现在我想编写一个方法,它 1) 检查路径是否以 '/en/ 或 '/fr/' 开头 2) 如果没有,则将值从另一个字符串中添加。
例如扩展方法
public static string ToLocaleRelativePath(this string s, string contextPath)
{
//1. Check if string begins with a locale
//2. If it does not prepend the value extracted from the context path
}
这样的操作适合扩展方法还是应该是实用程序?
谢谢
【问题讨论】:
标签: c# .net extension-methods