Take Sample Between Method

本文关键字:Method Between Sample Take | 更新日期: 2023-09-27 18:14:51

我得到这个错误:

方法'Extensions.Extensions. '的类型参数。Between(string, string, string)'不能从用法中推断出来。尝试显式指定类型参数。

    public static string Between<T>(this string Source, string First, string Second)
    {
        return Source.Split(new string[] { First }, StringSplitOptions.None)[1].Split(new string[] { Second }, StringSplitOptions.None)[0].Trim();
    }
string c = "abcd".Between("b", "d");

Take Sample Between Method

您有一个未被使用的泛型T,因此编译器无法推断它是哪种类型。你可以从你的方法中删除它:

public static string Between(this string Source, string First, string Second)
{
    return Source.Split(new string[] { First }, StringSplitOptions.None)[1].Split(new string[] { Second }, StringSplitOptions.None)[0].Trim();
}