求解释接口不能声明类型

Minaldo7 2017-05-21 03:39:07
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Test
{
class Program
{
public static void Main(string[] args)
{
IA ia = new IA();
A[0]=1;
Console.Read();

Console.ReadKey();
}
interface IA
{
// int[] Values
//{
// get;
// set;
//}
string this [int index]
{
get;
set;
}
public class A : IA
{
string[] values;
public string this [int index]
{
get
{
return values[index];
}
set
{
values[index] = value;
}
}
public A()
{
values = new string[10];
}
}
}

}
}


提示“Program.IA.A”:接口不能声明类型,小白求详解~
...全文
250 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Minaldo7 2017-05-22
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
你的 class A 跑到 interface IA 里面去了,要这样
        interface IA
        {
            // int[] Values
            //{
            //    get;
            //    set;
            //}
            string this[int index]
            {
                get;
                set;
            }
        }
        public class A : IA
        {
            string[] values;
            public string this[int index]
            {
                get
                {
                    return values[index];
                }
                set
                {
                    values[index] = value;
                }
            }
            public A()
            {
                values = new string[10];
            }
        }
原来是这里,这个大括号又出错了,谢谢你
Minaldo7 2017-05-22
  • 打赏
  • 举报
回复
引用 楼主 Su_Del 的回复:
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Test { class Program { public static void Main(string[] args) { IA ia = new IA(); A[0]=1; Console.Read(); Console.ReadKey(); } interface IA { // int[] Values //{ // get; // set; //} string this [int index] { get; set; } public class A : IA { string[] values; public string this [int index] { get { return values[index]; } set { values[index] = value; } } public A() { values = new string[10]; } } } } } 提示“Program.IA.A”:接口不能声明类型,小白求详解~
原来是这里,这个大括号又出错了,谢谢你
Minaldo7 2017-05-22
  • 打赏
  • 举报
回复
原来是这里,这个大括号又出错了,谢谢你
星空蔚蓝 2017-05-22
  • 打赏
  • 举报
回复
看来已经解决了啊
正怒月神 2017-05-22
  • 打赏
  • 举报
回复
IA ia = new IA(); 改成 IA ia = new A();
xuzuning 2017-05-21
  • 打赏
  • 举报
回复
你的 class A 跑到 interface IA 里面去了,要这样
        interface IA
        {
            // int[] Values
            //{
            //    get;
            //    set;
            //}
            string this[int index]
            {
                get;
                set;
            }
        }
        public class A : IA
        {
            string[] values;
            public string this[int index]
            {
                get
                {
                    return values[index];
                }
                set
                {
                    values[index] = value;
                }
            }
            public A()
            {
                values = new string[10];
            }
        }

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧