C# 字符串数组函数在C语言中的实现#

C# 字符串数组函数在C语言中的实现#,c#,arrays,string,indexer,C#,Arrays,String,Indexer,这是我大学C#windows窗体考试的结果,我试图解决一些老问题,但我似乎发现自己陷入了这种境地。这是我的代码: abstract class CarFile { private string marca; private readonly string serie; public CarFile(string marca, string serie) { this.marca = marca;

这是我大学C#windows窗体考试的结果,我试图解决一些老问题,但我似乎发现自己陷入了这种境地。这是我的代码:

  abstract class CarFile
    {
        private string marca;
        private readonly string serie;

        public CarFile(string marca, string serie)
        {
            this.marca = marca;
            this.serie = serie;
        }

        public string GetMarca
        {
            get { return this.marca; }
            set { this.marca = value; }
        }

        public string GetSerie
        {
            get { return this.serie; }
        }

        public abstract string GetDescriere();
    }
  public class MyException : System.Exception
    {
        public MyException(string mesaj) : base(mesaj) { }
    }
    class ServiceFile : CarFile, ICloneable, IComparable, IReparabil
    {
        string[] RepairComands;
        private enum motor {   motorina,     benzina,       GPL,     electric,     hibrid     };

        public ServiceFile(string serie, string marca, string[] RepairComands):base(serie,marca){
            if (serie == null)
            {
                throw new MyException("MESAJ");
            }
            this.RepairComands = RepairComands;



    }

        //not sure if this is correct
        public override string GetDescriere()
        {
            string msj = string.Format("the car {0} with serial {1} and necess. repairs {2}", this.GetMarca, this.GetSerie, this.RepairComands);
            return msj;
        }


        public object Clone()
        {
            ServiceFile clone = new ServiceFile(this.GetSerie, this.GetMarca, this.RepairComands);
            return clone;
        }

//implemented IComparable to be able to compare here 2 files by the number of repairs needed
            public int CompareTo(object obj)
            {
                ServiceFile altafisa = (ServiceFile)obj;
                if (this.RepairComands != altafisa.RepairComands)
                             return 1;
                    else return 0;
                }
//overloads ToString to return the complete file description

        public override string ToString()
        {
            return this.GetMarca + " "+ this.GetSerie + " " + this.RepairComands;
        }




    }
}
那么我必须这样做: 我的第二个类叫做ServiceFile:CarFile,ICloneable。在这个类中,我有一个名为RepairComands的数组或字符串列表,其中包含必要的修复。 -一种称为“马达”的私人心房肌,只能使用以下值{gas,gpl,hibrid}。 -如果“serie==null”,则引发泛型异常的构造函数 -重写abrstract方法getDescriere()以返回car文件的完整描述

这是我的代码:

  abstract class CarFile
    {
        private string marca;
        private readonly string serie;

        public CarFile(string marca, string serie)
        {
            this.marca = marca;
            this.serie = serie;
        }

        public string GetMarca
        {
            get { return this.marca; }
            set { this.marca = value; }
        }

        public string GetSerie
        {
            get { return this.serie; }
        }

        public abstract string GetDescriere();
    }
  public class MyException : System.Exception
    {
        public MyException(string mesaj) : base(mesaj) { }
    }
    class ServiceFile : CarFile, ICloneable, IComparable, IReparabil
    {
        string[] RepairComands;
        private enum motor {   motorina,     benzina,       GPL,     electric,     hibrid     };

        public ServiceFile(string serie, string marca, string[] RepairComands):base(serie,marca){
            if (serie == null)
            {
                throw new MyException("MESAJ");
            }
            this.RepairComands = RepairComands;



    }

        //not sure if this is correct
        public override string GetDescriere()
        {
            string msj = string.Format("the car {0} with serial {1} and necess. repairs {2}", this.GetMarca, this.GetSerie, this.RepairComands);
            return msj;
        }


        public object Clone()
        {
            ServiceFile clone = new ServiceFile(this.GetSerie, this.GetMarca, this.RepairComands);
            return clone;
        }

//implemented IComparable to be able to compare here 2 files by the number of repairs needed
            public int CompareTo(object obj)
            {
                ServiceFile altafisa = (ServiceFile)obj;
                if (this.RepairComands != altafisa.RepairComands)
                             return 1;
                    else return 0;
                }
//overloads ToString to return the complete file description

        public override string ToString()
        {
            return this.GetMarca + " "+ this.GetSerie + " " + this.RepairComands;
        }




    }
}
到目前为止还不错。这确实有效

但现在我的问题来了: 我必须定义接口IRep,它包含两个方法:void RepairCar()和void AddRepair(字符串修复)。 然后ServiceFile类实现:IRep,函数RepairCar()将用于从集合RepairComands中删除最后一次修复 函数AddRepair(字符串修复)将用于在集合RepairComands中添加修复。 (为了允许访问私有修复列表,我们应该重载索引运算符[])

非常感谢你的帮助,我是一名C#出身的学生,我只是想更好地理解课堂上教给我的这门课,这样我就可以学习了


谢谢你

这个问题是一个冗长的提问方式“如何在C#中创建和使用接口”还是“如何重载索引运算符”?如果是这样,你会在谷歌上找到很多简单的例子。你好,谢谢你的评论。我知道如何实现接口,我的问题是我不知道如何为这两个函数(repaircar和addrepair)编写代码来完成它们需要做的事情。您应该更新您的问题,以包括您拥有的所有相关代码。目前,您已经发布了一些代码,并询问了有关不存在的其他代码的问题。如果您知道占位符函数的外观,请添加占位符函数,我们可以帮助您填写它们的内容。你为自己做的越多,你在这个网站上得到的帮助就越多。