`
phoebird
  • 浏览: 113632 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

c# 机构的使用

    博客分类:
  • C#
阅读更多
using System;
using System.Collections.Generic;
using System.Text;

namespace Queue
{
    public struct Point//定义结构
    {

        public int x;
        public int y;
        //结构中无法定义参数的构造函数
        //public Point() { 
        
        //}
        public Point(int p1, int p2)//方法
        {
            x = p1;
            y = p2;
        }
    }
    class Test
    {
        static void Main(string[] args)
        {
            
            ////第一种、通过new 关键字创建对象
            //Point p1 = new Point();
            //Point p2 = new Point(10,10);
            //System.Console.Write("Point 1: ");
            //System.Console.WriteLine("x={0},y={1}", p1.x, p1.y);

            //System.Console.Write("Point 2: ");
            //System.Console.WriteLine("x={0},y={1}", p2.x, p2.y);
            //Console.ReadLine();

            ////输出:
            ////Point 1: x=0,y=0
            ////Point 2: x=10,y=10

            //第二种、定义数据对象
            Point p1;
            p1.x = 10;
            p1.y = 20;
            System.Console.Write("point 1:");
            System.Console.WriteLine("x={0};y={1}",p1.x,p1.y);
            Console.ReadLine();
            //输出:
            //point 1: x=10,y=20


        }
    }
   
  
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics