C#中结构struct的使用

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的使用的更多相关文章
- go语言中结构struct
package main; import "fmt" //结构struct //定义Person结构 type Person struct { name string; age i ...
- C#中结构(struct)的部分初始化和完全初始化
假设有这样一个值类型struct. public struct Size { public int Length; public int Width; public int Area() { retu ...
- C/C++中结构体struct 的使用
结构(struct) 结构是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合. 结构中可以使用不同的数据类型. 1. 结构说明和结构变量定义 在Turbo C ...
- C/C++中结构体(struct)
c++ 里面struct可以new,另外: C++中,struct关键字与Class关键字基本是一样的,但是,有两点不同 1 struct定义的数据类型里面所有成员默认级别都是共有的,而class里面 ...
- 《挑战30天C++入门极限》C/C++中结构体(struct)知识点强化
C/C++中结构体(struct)知识点强化 在上一个教程中我们已经简单的阐述了什么是结构体了,为了进一部的学习结构体这一重要的知识点,我们今天来学习一下链表结构. 结构体可以看做是一种自定义 ...
- C++中结构体与类的区别(struct与class的区别)
转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据 ...
- C语言中结构体赋值问题的讨论
今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...
- OC中结构体作为对象属性
在OC中结构体有时候也作为对象的属性 类的定义 #import <Foundation/Foundation.h> typedef struct{ int year; int month; ...
- c++中的struct
c++中的struct不在是c中的struct,不仅仅是一个多个数据类型的结构体了.c++中的struct可以具有成员函数(c语言中是不可以的),c++ struct还可以继承class等等.同时c+ ...
随机推荐
- vue组件的一些知识理解
组件我们在项目中会很常用到,说下自己在学习过程中的理解,有关 组件初始化顺序,组件为什么data是function,组件的生命周期 1. Vue.component('', {}) 注册全局组件,组 ...
- Pickling
Pickle translates almost any type of object into a string. pickle.dumps takes an object as a paramet ...
- 安卓开发--HttpClient
package com.zx.httpclient01; import android.app.Activity; import android.os.Bundle; import android.v ...
- SharePoint 第一个网站
第一个网站 1.建立一个社区门户网站首先要建一个IIS网站,并且把匿名访问勾选上,这样才能真正的访问网站. 创建网站的时候更改自己想要的端口,以便操作 这里更改网站是否启用匿名访问权限.点击是 然后保 ...
- PHP万能的连接数据库
<?php class DB{ const HOST='127.0.0.1'; const USER='root'; const PASS='root'; const DATA='mooc'; ...
- 基于Struts2+MySQL的多表出差明细表单
下载地址:http://download.csdn.net/detail/qq_33599520/9790629 项目结构: UserAction package com.mstf.action; i ...
- Data flow diagram-数据流图
A DFD shows what kind of information will be input to and output from the system, how the data will ...
- caffe(13) 数据可视化(python接口)配置
caffe程序是由c++语言写的,本身是不带数据可视化功能的.只能借助其它的库或接口,如opencv, python或matlab.大部分人使用python接口来进行可视化,因为python出了个比较 ...
- ES6学习笔记(十五)Generator函数的异步应用
1.传统方法 ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发布/订阅 Promise 对象 Generator 函数将 JavaScript 异步编程带入了一个全新的阶段. ...
- CodeForces 312B Archer
Archer Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ...