[Mono-list] Derived classes returning an object that is derived

Daniel Morgan danmorg@sc.rr.com
Sun, 14 Apr 2002 12:52:41 -0400


Hello,

I have a general C# question about interfaces and their derived classes.
I've been pulling my hair out on this.  How is the function
CreateParameter in Command supposed to be defined?

I have provided the code below.

// TestParameterReturnType.cs
//
// Test case to get "does not implement interface member ... either
//   static, not public, or has the wrong return type"

using System;

namespace MyStuff
{
	interface IParameter
	{
		string ParameterName{get;set;}
	}

	public class Parameter : IParameter 
	{
		private string parmName = null;

		public string ParameterName 
		{
			get 
			{
				return parmName;
			}

			set 
			{
				parmName = value;
			}
		}
	}

	interface ICommand
	{
		IParameter CreateParameter();
	}

	public class Command : ICommand
	{
		public Parameter CreateParameter()
		{
			Parameter parm = new Parameter();
			return parm;
		}
	}

	class MainDriver
	{
		[STAThread]
		static void Main(string[] args)
		{
			SqlCommand cmd = new SqlCommand();		
		}
	}
}