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;
            }
           }
    }
  • 相关阅读:
    spring jdbc和spring mybatis没什么很大的区别,为什么要用mybatis优势在哪里
    spring概述及环境搭建
    一些关于使用分区视图的好主意(转)
    正确选择排序提高查询性能(转)
    线程池的原理和连接池的原理
    编程式事务造成的系统频繁Down机的前后
    《Oracle 高效设计》 读书思考标量子查询查询性能讨论
    ORACLE自动备份方法(转)
    Oracle 10gR2 行变列研究
    索引组织表IOT(转)
  • 原文地址:https://www.cnblogs.com/wordgao/p/4465060.html
Copyright © 2011-2022 走看看