using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Demo
{
enum orientation:byte
{
北 = 1,
南 = 2,
东 = 3,
西 = 4
} struct route
{
public orientation direction;
public double distance;
}
class Program
{
static void Main(string[] args)
{
route myRoute;
int myDirection = -1;
double myDistance;
Console.WriteLine("1)北\n 2)南\n 3)东\n 4)西\n");
do
{
Console.WriteLine("选择一个方向:");
myDirection = Convert.ToInt16(Console.ReadLine());
} while (myDirection < 1 || myDirection > 4); Console.WriteLine("输入一个距离:");
myDistance = Convert.ToDouble(Console.ReadLine()); myRoute.direction = (orientation)myDirection;
myRoute.distance = myDistance; Console.WriteLine("方向是{0},距离是{1}!",myRoute.direction,myRoute.distance); Console.ReadKey();
}
}
}

结构比枚举更复杂,可以保存多种类型的数据!

C#中结构struct的使用的更多相关文章

  1. go语言中结构struct

    package main; import "fmt" //结构struct //定义Person结构 type Person struct { name string; age i ...

  2. C#中结构(struct)的部分初始化和完全初始化

    假设有这样一个值类型struct. public struct Size { public int Length; public int Width; public int Area() { retu ...

  3. C/C++中结构体struct 的使用

    结构(struct)      结构是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合.  结构中可以使用不同的数据类型.      1. 结构说明和结构变量定义      在Turbo C ...

  4. C/C++中结构体(struct)

    c++ 里面struct可以new,另外: C++中,struct关键字与Class关键字基本是一样的,但是,有两点不同 1 struct定义的数据类型里面所有成员默认级别都是共有的,而class里面 ...

  5. 《挑战30天C++入门极限》C/C++中结构体(struct)知识点强化

        C/C++中结构体(struct)知识点强化 在上一个教程中我们已经简单的阐述了什么是结构体了,为了进一部的学习结构体这一重要的知识点,我们今天来学习一下链表结构. 结构体可以看做是一种自定义 ...

  6. C++中结构体与类的区别(struct与class的区别)

    转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据 ...

  7. C语言中结构体赋值问题的讨论

    今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...

  8. OC中结构体作为对象属性

    在OC中结构体有时候也作为对象的属性 类的定义 #import <Foundation/Foundation.h> typedef struct{ int year; int month; ...

  9. c++中的struct

    c++中的struct不在是c中的struct,不仅仅是一个多个数据类型的结构体了.c++中的struct可以具有成员函数(c语言中是不可以的),c++ struct还可以继承class等等.同时c+ ...

随机推荐

  1. http --- 从输入URL到页面加载的过程发生了什么?

    可以分为这几个大的过程: DNS解析 TCP连接 客户端发送HTTP请求 服务器处理请求并返回HTTP报文 浏览器解析渲染页面 结束 其中(1)DNS解析可以理解为主寻找这个IP地址的过程,其中如果找 ...

  2. Reading and writing

    A text file is a sequence of characters stored on a permanent medium like a hard drive, flash memory ...

  3. 如何让alertdialog选择完后自动关闭

    builder.setIcon(R.drawable.ic_system) .setTitle("串口号") .setSingleChoiceItems(mPorts, mSele ...

  4. Swift学习笔记(5):集合类型

    目录: 数组:Array 集合:Set 字典:Dictionary Swift提供Array(有序集合数据).Set(无序无重复集合)和Dictionary(无序键值对集合)三种基本集合类型来存储明确 ...

  5. canvas指定的宽高写在行间和写在style里面的区别?

    上代码,指定的canvas宽高都一样,线条的粗细都是5px 1.宽:400:高:300:直接写在<canvas>里的效果: 2.删除<canvas>里的宽高,宽:400:高:3 ...

  6. 200 from memory cache / from disk cache / 304 Not Modified 区别

    三者情况有什么区别和联系,什么情况下会发生200 from memory cache 或 200 from disk cache 或 304 Not Modified? 200 from memory ...

  7. vuejs fatherandson

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Map<String,String>转换json字符串

    import java.util.HashMap; import java.util.Map; import net.sf.json.JSONObject; public class testJson ...

  9. CentOS7.4-btrfs管理及使用

    btrfs, B-tree File System, GPL开源文件系统, 支持CoW即读时写入. 核心特性: 多物理卷支持; btrfs可由多个底层磁盘组成 支持RAID mkfs.btrfs 命令 ...

  10. 安装Orcacle后使用DBCA(Database Configuration Assistant)卡住的问题

    转自:http://hi.baidu.com/kissbaofish/item/2f56d326742c39454799620b 用dbca建库停在46% 是export NLS_LANG='amer ...