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. (转)建站知识:域名/ 空间/ IP/ 端口之间的关系

    先说域名解析吧,比如说你的域名是 www.sunnymould.com,这个域名对应着一个IP地址,域名解析就是把上面的域名转换成这个IP地址的过程,这样你就可以域名访问了上面地址上的内容了. 端口映 ...

  2. CentOS 7数据库mysql和mariadb手动安装冲突的问题解决

    由于确定使用mysql,那只有卸载mariadb了. 一.首先查看当前安装的mariadb包 rpm -qa|grep mariadb 本人得到结果是:mariadb-libs-5.5.44-2.el ...

  3. Web服务器amp搭建

  4. oracle数据库的TNS配置

    TNS简要介绍与应用 Oracle中TNS的完整定义:transparence Network Substrate透明网络底层,监听服务是它重要的一部分,不是全部,不要把TNS当作只是监听器. TNS ...

  5. C#:类和结构的区别

    第一.引用类型和值类型 类属于引用类型,而结构属于值类型. 结构在赋值时进行复制. 将结构赋值给新变量时,将复制所有数据,并且对新副本所做的任何修改不会更改原始副本的数据. 第二.继承性 类可以继承类 ...

  6. Deep Learning Papers Reading Roadmap

    Deep Learning Papers Reading Roadmap https://github.com/songrotek/Deep-Learning-Papers-Reading-Roadm ...

  7. maven环境快速搭建

    ----------------准备工作------------- Jdk  1.5以上java开发环境. Eclipse IDE 一个. Maven 3.0.3下载地址: http://maven. ...

  8. js之oop <五>对象序列化(js的JSON操作)

    js对象序列化的过程,就是对象转换为JSON的过程.JSON.stringify() 将对象序列化成JSON.(接收对象,输出字符串) var obj = {x:2,y:3}; var str = J ...

  9. Java通过jedis操作redis缓存

    package com.wodexiangce.util; import java.util.Set; import redis.clients.jedis.Jedis; /** * redis工具类 ...

  10. codeforces 446A DZY Loves Sequences

    vjudge 上题目链接:codeforces 446A 大意是说最多可以修改数列中的一个数,求最长严格递增的连续子序列长度. 其实就是个 dp 的思想,想好思路后交上去没想到一直 wa 在第二个测试 ...