Compile error: "type parameter declaration must be an identifier nota type"

J

Jazer

I have a couple of classes that implement an interface with a generic
method:

interface IMyInterface {
string Name { get; set; };
T DoSomething<T>();
}

abstract class BaseDoingSomething : IMyInterface {
private string _name = "My Name";
public string Name {
get { return _name; }
set { _name = value; }
}

public abstract T DoSomething<T>();
}

class MyDoingSomething : BaseDoingSomething {
public override IList<string> DoSomething<IList<string>>()
{
// do something that results in a IList<string>
return myListOfString;
}
}

this results in the CS0081: type parameter declaration must be an
identifier not a type
I thought this was a valid use of compile-time typing. No?

Thanks!
B.
 
I

Ignacio Machin ( .NET/ C# MVP )

I have a couple of classes that implement an interface with a generic
method:

interface IMyInterface {
    string Name { get; set; };
    T DoSomething<T>();

}

abstract class BaseDoingSomething : IMyInterface {
    private string _name = "My Name";
    public string Name {
        get { return _name; }
        set { _name = value; }
    }

    public abstract T DoSomething<T>();

}

class MyDoingSomething : BaseDoingSomething {
    public override IList<string> DoSomething<IList<string>>()
    {
        // do something that results in a IList<string>
        return myListOfString;
    }

}

this results in the CS0081: type parameter declaration must be an
identifier not a type
I thought this was a valid use of compile-time typing.   No?

Thanks!
B.

Hi,

You are not implementing T DoSomething<T>() , you are implementing
IList<string> DoSomething<IList<string>> . This prevent that a caller
call it with something like DoSomething<OtherType>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top