[C#학습노트] 클래스 구조 함수 사용

2421 단어
using System;

namespace ConsoleApplication
{
    class stu
    {
        private string name;
        private int age;

        public stu()
        {
            name = "";
            age = -1;
        }

        public stu(string n, int a)
        {
            name = n;
            age = a;
        }

        public void Print()
        {
            Console.Write(name + ":" + age);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            stu a=new stu("xiaoming",10);
            a.Print();

            Console.WriteLine();
            stu b = new stu();
            b.Print();

            Console.Read();
        }      
    }
}

 
전재 대상:https://www.cnblogs.com/tiandsp/p/7440428.html

좋은 웹페이지 즐겨찾기