zoukankan      html  css  js  c++  java
  • C# 程序开始主要是写类和方法 的基本步骤和调用方法

    主程序的使用方式以及调用方法
    字段、属性、方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime;
    using System.Runtime.InteropServices;
    
    namespace demo学习控制
    {
        class Program
        {
    
    
    
            static void Main(string[] args)
            {
                Stuiden adsme = new Stuiden();
                adsme.Bireday = Convert.ToDateTime("1983-02-03");
                Console.WriteLine("我的年龄是:" + adsme.age + "  " + "测试的结果完成了。");
                Console.ReadKey();
    
                //Console.Write("{0}*{1}", (1 == 2 ? 3 : 4) / 2, "10");
                Console.ReadKey();
    
    
            }
    
    
      
        }
    }

    类的信息

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace demo学习控制
    {
        class Stuiden
        {
            private DateTime bireday;
    
            public DateTime Bireday
            {
                get { return bireday; }
                set { bireday = value; }
            }
            public int age
            {
                get { return DateTime.Now.Year - bireday.Year; }
            }
    
            
    
        }
    }

    参照样例二

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace demo学习类的方法
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                Class1 ads = new Class1();
                Console.WriteLine("请输入您的名字");
                ads.Usname1 = Console.ReadLine();
                try
                {
                    Console.WriteLine("请输入您的年龄");
                    ads.Age1 = Convert.ToInt32(Console.ReadLine());
                    
                }
                catch
                {
                    Console.WriteLine("您输入的信息有误,请重新输入");
                    return;
                }
                string info = ads.Getinfots();
                //Console.WriteLine(info);            
                //Console.WriteLine(Uname);            
                Console.ReadKey();
    
    
            }
        }
    }

    样例二的类(读写访问权限自己修改)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace demo学习类的方法
    {
    
         
    
        class Class1
        {
    
            private string Usname;
    
            public string Usname1
            {
                get { return Usname; }
                set { Usname = value; }
            }
            private int Age;
    
            public int Age1
            {
                get { return DateTime.Now.Year - Age; }
               
            }
            public string Getinfots()
            {
    
                string info = string.Format("我的名字:{0},我的年龄:{1}", Usname, Age);
                return info;
            }
           }
    }
  • 相关阅读:
    Dp~Hrbust1426( 集训队的晚餐 )
    DP~数塔(hrbustoj1004)
    MyEclipse启动性能优化(----加快启动速度)
    很实用的php的缓存类文件示例
    PHP中9大缓存技术总结
    微信公众平台开发(76) 获取用户基本信息
    js中 onreadystatechange 和 onload的区别
    一个js文件导入js的函数
    PHP cURL实现模拟登录与采集使用方法详解教程
    Mysql清空表(truncate)与删除表中数据(delete)的区别
  • 原文地址:https://www.cnblogs.com/wordgao/p/4465060.html
Copyright © 2011-2022 走看看