Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET4函数:函数参数问题_C#_.net_Asp.net Mvc_.net 4.0 - Fatal编程技术网

C# .NET4函数:函数参数问题

C# .NET4函数:函数参数问题,c#,.net,asp.net-mvc,.net-4.0,C#,.net,Asp.net Mvc,.net 4.0,我正在关注一个关于.NET4框架的问题。本教程创建了如下函数 using System.Web; using System.Web.Mvc; namespace vohministries.Helpers { public static class HtmlHelpers { public static string Truncate(this HtmlHelper helper, string input, int length) {

我正在关注一个关于.NET4框架的问题。本教程创建了如下函数

using System.Web;
using System.Web.Mvc;

namespace vohministries.Helpers
{
    public static class HtmlHelpers
    {
        public static string Truncate(this HtmlHelper helper, string input, int length)
        {
            if (input.Length <= length)
            {
                return input;
            }
            else
            {
                return input.Substring(0, length) + "...";
            }
        }
    }
}
使用System.Web;
使用System.Web.Mvc;
名称空间vohministrates.Helpers
{
公共静态类HtmlHelpers
{
公共静态字符串截断(此HtmlHelper帮助程序,字符串输入,int-length)
{
如果(input.Length它是一个(从C#3.0开始出现):

扩展方法允许您“添加” 方法在不使用 创建新的派生类型, 重新编译或以其他方式修改 原始类型。扩展方法 是一种特殊的静态方法, 但他们被称为好像他们是 扩展类型上的实例方法。 对于用C#和 VisualBasic中,没有明显的 调用 扩展方法和 实际上是在类型中定义的


您可以通过两种方式调用该扩展方法:

HtmlHelpers.Truncate(helper, input, length)


这是最棒的,但它们是3.5版的功能;)哦!谢谢。我可以发誓我在2.0版中使用过它们!
helper.Truncate(input, length)