A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 面朝大海,春暖 中级黑马   /  2013-10-6 15:01  /  1302 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 面朝大海,春暖 于 2013-10-6 15:11 编辑

如下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {


            onePerson one = new onePerson("黎明","男",32);
            Console.WriteLine(one.name,one.sex,one.age);

            Console.ReadKey();
        }

        public struct onePerson
        {
            public string name;
            public string sex;
            public int age;
            //成员函数
            public void opp()
            {
            //内容
            }
           //构造函数
            public void   onePerson(string Name,string Sex,int Age)
            {
                name = Name;
                sex = Sex;
                age = Age;

            }

        }
    }


}

上述代码不能声明构造函数,说成员名与封闭类型相同,怎么回事

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

2 个回复

倒序浏览
public onePerson(string Name,string Sex,int Age)
            {
                name = Name;
                sex = Sex;
                age = Age;

            }
构造函数没有任何的返回值修饰符,连void都不需要

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

回复 使用道具 举报
谢谢!!!!!!!!!!!!!!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马