如何将以下这个类转换成xml文件输出
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:2.0.50727.3053
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------using System.Xml.Serialization;// 
// 此源代码由 xsd 自动生成, Version=2.0.50727.3038。
// 
/// <res/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class root {
    
    private string userNameField;
    
    private string sexField;
    
    private rootCourseCourseName[][] courseField;
    
    /// <res/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string UserName {
        get {
            return this.userNameField;
        }
        set {
            this.userNameField = value;
        }
    }
    
    /// <res/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string Sex {
        get {
            return this.sexField;
        }
        set {
            this.sexField = value;
        }
    }
    
    /// <res/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("CourseName", typeof(rootCourseCourseName), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public rootCourseCourseName[][] Course {
        get {
            return this.courseField;
        }
        set {
            this.courseField = value;
        }
    }
}/// <res/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class rootCourseCourseName {
    
    private string valueField;
    
    /// <res/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public string Value {
        get {
            return this.valueField;
        }
        set {
            this.valueField = value;
        }
    }
}/// <res/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class NewDataSet {
    
    private root[] itemsField;
    
    /// <res/>
    [System.Xml.Serialization.XmlElementAttribute("root")]
    public root[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }
}

解决方案 »

  1.   


     static void Main(string[] args)
            {            rootCourseCourseName rName = new rootCourseCourseName();
                rName.Value = "历史";
                rootCourseCourseName[][] RN = { new rootCourseCourseName[] { rName }, new rootCourseCourseName[] { rName, rName } };
                root Root = new root();
                Root.UserName = "刘备";
                Root.Sex = "男";
                Root.Course = RN;
                string filePath = "c:/test.xml";           
                XmlSerializer xs = new XmlSerializer(typeof(root));//代码运行到这里就报错了
                Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                xs.Serialize(stream, Root);
                stream.Close();        }
    无法生成临时类(result=1)。
    error CS0030: 无法将类型“rootCourseCourseName[]”转换为“rootCourseCourseName”
    error CS0029: 无法将类型“rootCourseCourseName”隐式转换为“rootCourseCourseName[]”
      

  2.   

    改Course属性的XmlArrayItemAttribute特性为如下:
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("CourseName", typeof(rootCourseCourseName[]), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public rootCourseCourseName[][] Course {
    }
    因为Course 是二位数组,其子项应是一维数组。