C# 代码示例_结构/数组/枚举...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1
{
class Program
{
//Enum Definition
enum orientation : byte
{
north=,
south=,
east=,
west=
} //Structure Definition
struct route
{
public orientation direction;
public double distance;
} static void Main(string[] args)
{
#region regionTest
Console.WriteLine("From the beginning again.");
Console.ReadLine();
#endregion //Type Conversion
/* Keyword for OverflowException check: checked, unchecked
* or you can configure the application:
* 1) Right click the project in Solution Explorer panel,select 'Properties' from context menu
* 2) Select 'Build' in the left navigation bar, click 'Advanced' button.
* 3) Tick off 'Check for arithmetic overflow/underflow' checkbox, click 'OK'.
*/
byte destinationVar;
short sourcevar = ;
destinationVar = checked((byte)sourcevar); //will popup an error when running
Console.WriteLine("destinationVar val:{0}", destinationVar); //Enum practice
byte directionByte;
string directionString;
orientation myDirection = orientation.north;
Console.WriteLine("myDirection = {0}",myDirection);
directionByte = (byte)myDirection; //must use explicit conversion even though it's of byte. //enum to string
directionString = Convert.ToString(myDirection);
directionString = myDirection.ToString(); // same rsult as the one above
Console.WriteLine("byte equivalent = {0}",directionByte);
Console.WriteLine("string equivalent={0}",directionString); //string to enum
string myString = "east";
orientation yourDirection = (orientation)Enum.Parse(typeof(orientation), myString); ////Struct practice
route myRoute;
int intDirection = -;
double doubleDistence;
Console.WriteLine("1) North\t2) South\t3) East\t4) West");
do
{
Console.WriteLine("Select a direction:");
intDirection = Convert.ToInt32(Console.ReadLine());
} while (intDirection < || intDirection > );
Console.WriteLine("Input a distance:");
doubleDistence = Convert.ToDouble(Console.ReadLine());
myRoute.direction = (orientation)intDirection;
myRoute.distance = doubleDistence;
Console.WriteLine("myRoute specifies a direction of {0} and a distance of {1}.", myRoute.direction, myRoute.distance); //Array Definition
int[] firstArrary = {,,,,};
int[] secondArray=new int[];
int[] thirdArrary = new int[] { ,,}; //the number should be the same.
const int count = ;
int[] forthArray = new int[count]; //multidimensional array
double[,] multiArray1 = new double[, ];
double[,] multiArray2 = { {,},{,},{,}}; //jagged array
int[][] jaggedArray = new int[][];
jaggedArray[]=new int[];
jaggedArray[] = new int[]; int[][] jaggedArray2 = { new int[]{,}, new int[]{}, new int[]{,}};
foreach (int[] divisorsOfInt in jaggedArray2)
{
foreach (int divisor in divisorsOfInt)
{
Console.WriteLine(divisor);
}
} //String Manipulation
string mystring = "Happy New Year";
char[] mychars = mystring.ToCharArray();
foreach (char character in mystring)
{
Console.WriteLine("{0}", character);
} Console.ReadLine(); }
}
}
C# 代码示例_结构/数组/枚举...的更多相关文章
- [C语言]贪吃蛇_结构数组实现
一.设计思路 蛇身本质上就是个结构数组,数组里存储了坐标x.y的值,再通过一个循环把它打印出来,蛇的移动则是不断地刷新重新打印.所以撞墙.咬到自己只是数组x.y值的简单比较. 二.用上的知识点 结构数 ...
- C#代码示例_定义类
默认情况下,类声明为内部的,即只有当前项目中的代码才能访问它.可以使用internal访问修饰符关键字显示指定. 除了两个访问修饰符关键字(public, internal)外,还可以指定类是抽象的( ...
- C#代码示例_函数
参数数组 C#允许为函数指定一个(只能指定一个)特定的参数,这个参数必须是函数定义中的最后一个参数,称为参数数组.参数数组可以使用个数不定的参数调用函数,可以使用params关键字定义它们. 参数数组 ...
- C#代码示例_调试
调试信息 可使用如下两个命令输出调试信息: l Debug.WriteLine() l Trace.WriteLine() 这两个命令函数的用法几乎完全相同,但有一个重要区别.第一个命令仅在调试模式下 ...
- 强化学习 reinforcement learning: An Introduction 第一章, tic-and-toc 代码示例 (结构重建版,注释版)
强化学习入门最经典的数据估计就是那个大名鼎鼎的 reinforcement learning: An Introduction 了, 最近在看这本书,第一章中给出了一个例子用来说明什么是强化学习, ...
- C#代码示例_集合
C#中数组实现为System.Array类得实例,它们只是集合类(Collection Classes)中的一种类型. 索引符(indexer)是一种特殊类型的属性,可以把它添加到一个类中,以提供类似 ...
- C++_知识点_结构体/枚举/联合
//C++中结构体的不同之处 #include <iostream> #include <string> using namespace std; int main(void) ...
- 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好
HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...
- C#编程利器之二:结构与枚举(Structure and enumeration)【转】
C#编程利器之二:结构与枚举(Structure and enumeration) 在上一篇文章中,介绍了类如何封装程序中的对象.而实际中,出了类可以封装对象外,结构和枚举也可以封装一些对象,本文将着 ...
随机推荐
- linux 循环处理文件夹下所有文件脚本
#!/bin/bashfunction ergodic(){ for file in ` ls $1 ` do if [ -d $1"/"$file ] then ergodic ...
- 制作图片边框:《CSS3 Border-image》
一个边框图片border-image
- chrome 开发者工具详解
Google Chrome一共提供了8大组工具: Elements: 允许我们从浏览器的角度看页面,也就是说我们可以看到chrome渲染页面所需要的的HTML.CSS和DOM(Document Obj ...
- python os模块(1)
os模块主要处理文件和目录(文件夹)的创建.删除.检查判定.属性值修改.路径修改. (1)获取当前目录的两种方法 1 os.getcwd() os.path.abspath('.') (2)创建文件夹 ...
- 【转载】C++中的位拷贝和值拷贝
---恢复内容开始--- 原文:C++中的位拷贝和值拷贝 原文:http://blog.csdn.net/liam1122/article/details/1966617 为了便于说明我们以Strin ...
- maven环境快速搭建
----------------准备工作------------- Jdk 1.5以上java开发环境. Eclipse IDE 一个. Maven 3.0.3下载地址: http://maven. ...
- Zookeeper第一课 安装和配置
简介: Zookeeper,是Google的Chubby一个开源的实现,是Hadoop的分布式协调服务,它包含一个简单的原语集,来实现同步.配置维护.分集群.命名的服务. zookeeper是一个由多 ...
- 关于分布式事务、两阶段提交、一阶段提交、Best Efforts 1PC模式和事务补偿机制的研究 转载
1.XA XA是由X/Open组织提出的分布式事务的规范.XA规范主要定义了(全局)事务管理器(Transaction Manager)和(局部)资源管理器(Resource Manager)之间的接 ...
- mysql的初识--DOS下的简单命令
DOS下进入 1.通过程序中的mySQL的:MySQL 5.6 Command Line Client直接进入mySQL的命令行: 2.或者通过WIn+R-->输入cmd,然后C:等一层一层找到 ...
- 使用Android点击按钮跳转页面
1.首先新建一个Android工程,命名为MyApp(名字可以自己随意起); 2.以原有的MainActivity.java文件为登录界面,然后在src文件中的包上面右击选择New目录下的Other中 ...