注册 登录
编程论坛 C# 论坛

新手编程,求解,我运行不出结果,大家可帮我看看是不是哪里出错了?

t120653918 发布于 2014-07-18 11:36, 781 次点击
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Student std1 = new Student();
            std1.stdno = "2013080452";
            std1.stdName = "张三";
            std1.stdSex = "男";
            std1.stdBir = new DataTime(1992, 1, 12);

            int age = std1.getAge();
            Console.WriteLine(age);

            Student std2 = new Student();
            std2.stdbir = new DataTime(1989, 5, 12);

            int age2 = std2.getAge();
            Console.WriteLine(age2);
        }
    }
}

class Student
{
    public string stdno;
    public string stdName;
    public string stdSex;
    public string stdBir;

    int getAge();
    {
        DaTatime nowTime=DaTatime.Now;
    return nowTime.Year-stdBir.Year;
    }
}
5 回复
#2
Maick2014-07-18 13:21
public string stdBir;
这个是string 类型..改成dataTime类型
#3
yanglin_gdqy2014-07-31 02:05
接上,int getAge()后多了一个分号
#4
姚星星772014-09-12 09:42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
      public   static void Main(string[] args)
        {
            Student std1 = new Student();
            std1.stdno = "2013080452";
            std1.stdName = "张三";
            std1.stdSex = "男";
            std1.stdBir = new DateTime(1992, 1, 12);

            int age = std1.getAge();
            Console.WriteLine(age);

            Student std2 = new Student();
            std2.stdBir = new DateTime(1989, 5, 12);

            int age2 = std2.getAge();
            Console.WriteLine(age2);
            Console.ReadKey();
        }
    }
}

            public class Student
            {
                public string stdno;
                public string stdName;
                public string stdSex;
                public DateTime stdBir;

               public  int getAge()
                {
                    DateTime nowTime=DateTime.Now;
                    return nowTime.Year-stdBir.Year;
                }
            }
#5
邓士林2014-09-12 10:25
赞一个,其实你那不叫不出结果,而是报错,Error
#6
Misuzu2014-09-29 10:46
更新的新手表示学到了一点东西呢。。
1