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# 代码示例_结构/数组/枚举...的更多相关文章

  1. [C语言]贪吃蛇_结构数组实现

    一.设计思路 蛇身本质上就是个结构数组,数组里存储了坐标x.y的值,再通过一个循环把它打印出来,蛇的移动则是不断地刷新重新打印.所以撞墙.咬到自己只是数组x.y值的简单比较. 二.用上的知识点 结构数 ...

  2. C#代码示例_定义类

    默认情况下,类声明为内部的,即只有当前项目中的代码才能访问它.可以使用internal访问修饰符关键字显示指定. 除了两个访问修饰符关键字(public, internal)外,还可以指定类是抽象的( ...

  3. C#代码示例_函数

    参数数组 C#允许为函数指定一个(只能指定一个)特定的参数,这个参数必须是函数定义中的最后一个参数,称为参数数组.参数数组可以使用个数不定的参数调用函数,可以使用params关键字定义它们. 参数数组 ...

  4. C#代码示例_调试

    调试信息 可使用如下两个命令输出调试信息: l Debug.WriteLine() l Trace.WriteLine() 这两个命令函数的用法几乎完全相同,但有一个重要区别.第一个命令仅在调试模式下 ...

  5. 强化学习 reinforcement learning: An Introduction 第一章, tic-and-toc 代码示例 (结构重建版,注释版)

    强化学习入门最经典的数据估计就是那个大名鼎鼎的  reinforcement learning: An Introduction 了,  最近在看这本书,第一章中给出了一个例子用来说明什么是强化学习, ...

  6. C#代码示例_集合

    C#中数组实现为System.Array类得实例,它们只是集合类(Collection Classes)中的一种类型. 索引符(indexer)是一种特殊类型的属性,可以把它添加到一个类中,以提供类似 ...

  7. C++_知识点_结构体/枚举/联合

    //C++中结构体的不同之处 #include <iostream> #include <string> using namespace std; int main(void) ...

  8. 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好

    HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...

  9. C#编程利器之二:结构与枚举(Structure and enumeration)【转】

    C#编程利器之二:结构与枚举(Structure and enumeration) 在上一篇文章中,介绍了类如何封装程序中的对象.而实际中,出了类可以封装对象外,结构和枚举也可以封装一些对象,本文将着 ...

随机推荐

  1. 深入理解为什么Java中方法内定义的内部类可以访问方法中的局部变量

    好文转载:http://blog.csdn.net/zhangjg_blog/article/details/19996629 开篇 在我的上一篇博客 深入理解Java中为什么内部类可以访问外部类的成 ...

  2. Tsung安装与使用

    Tsung安装与使用 Tsung安装与使用的详细说明,包括测试场景的脚本配置说明 Ray 2013/11/11   目录 安装tsung Tsung运行环境安装... Tsung安装... 使用Tsu ...

  3. BFS AOJ 0558 Chess

    AOJ 0558 Chess http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0558    在H * W的地图上有N个奶酪工厂,每个 ...

  4. Windows7开通Internet信息服务

      我要开通Windows的Internet Information Service(也就是Internet信息服务,简称IIS),当本地服务器用,因为要在里面安装页面项目.    我参考了这篇文章的 ...

  5. [问题2014A02] 复旦高等代数 I(14级)每周一题(第四教学周)

    [问题2014A02]  求下列 \(n\) 阶行列式的值, 其中 \(a_i\neq 0\,(i=1,2,\cdots,n)\): \[ |A|=\begin{vmatrix} 0 & a_ ...

  6. Python3基础 int(input())输入数字并产生一个int类型变量

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  7. ZooKeeper 编程(一)

    Zookeeper的节点都是存放在内存中的,所以读写速度很快.更新日志被记录到了磁盘中,以便用于恢复数据.在更新内在中节点数之前,会先序列化到磁盘中. 为避免单点失效,zookeeper的数据是在多个 ...

  8. poj 3321 Apple Tree dfs序+线段树

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K       Description There is an apple tree outsid ...

  9. 单据状态BE构建

    这节主要罗列出单据状态BE构建步骤1.创建单据状态BE实体项目,修改命名空间 2.如下图所示,分别设置实体枚举状态值 3.修改单据基本属性 构造后,至此单据状态BE构建完毕

  10. 浅谈JavaScript中的闭包

    浅谈JavaScript中的闭包 在JavaScript中,闭包是指这样一个函数:它有权访问另一个函数作用域中的变量. 创建一个闭包的常用的方式:在一个函数内部创建另一个函数. 比如: functio ...