Beginner with c# 5

1。5 数组类型(Array types)

数组可以是一维的,也可是多维的。数祖的成员可以是整齐的,也可以是变长(jagged)的。

一维的数组是最普通,最简单的。这里值给出一个例子,就不多解释了。*/
using System;
class Test
{
static void Main() {
int[] arr = new int[5];
for (int i = 0; i < arr.Length; i++)
arr[i] = i * i;
for (int i = 0; i < arr.Length; i++)
Console.WriteLine("arr[{0}] = {1}", i, arr[i]);
}
}

/* 结果如下:
arr[0] = 0
arr[1] = 1
arr[2] = 4
arr[3] = 9
arr[4] = 16

我们还可以比较的看看多维,规则,变长的数组的定义和赋值:*/
class Test
{
static void Main() {
int[] a1 = new int[] {1, 2, 3}; //一维
int[,] a2 = new int[,] {{1, 2, 3}, {4, 5, 6}}; //二维
int[,,] a3 = new int[10, 20, 30]; //三维
int[][] j2 = new int[3][]; //变长
j2[0] = new int[] {1, 2, 3};
j2[1] = new int[] {1, 2, 3, 4, 5, 6};
j2[2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
}
}
/*
上面的例子给出了各种样式的数组。变量a1、a2和a3是规则数组。j2则是变长的数组。
规则数组很容易就可以计算出它们的长度。比如a3的长度是:10*20*30=6000。相反,变长
数组就有点不同,它的每一个维度都必须单独定义。如j2的第一维度是3,第二个是6,第
三个是9,所以总长度是:1*3+1*6+1*9=18。

上面对数组的赋值是严谨的风格,在某种情况下,我们可以简化写法,但我总觉得这种简化
应用限制太多,容易出错。在这里就不作介绍了。这里再给一个例子说明函数中的参数如何
赋值*/
class Test
{
static void F(long[] arr) {}
static void Main() {
F(new longt[] {1, 2, 3});
}
}

时间: 2024-11-17 11:49:21

Beginner with c# 5的相关文章

新手教程之:循环网络和LSTM指南 (A Beginner’s Guide to Recurrent Networks and LSTMs)

  新手教程之:循环网络和LSTM指南 (A Beginner's Guide to Recurrent Networks and LSTMs)   本文翻译自:http://deeplearning4j.org/lstm.html   其他相关教程: 1. 深度神经网络简介 http://deeplearning4j.org/zh-neuralnet-overview 2. 卷积网络 http://deeplearning4j.org/zh-convolutionalnets   目录: 1.

(转)A Beginner&amp;#39;s Guide To Understanding Convolutional Neural Networks Part 2

Adit Deshpande CS Undergrad at UCLA ('19) Blog About A Beginner's Guide To Understanding Convolutional Neural Networks Part 2 Introduction Link to Part 1                 In this post, we'll go into a lot more of the specifics of ConvNets. Disclaimer:

Beginner: Using Servlets to display, insert and update records in database.(1)

servlet Displaying Records from the Database with Java Servlets. Overview : In this article I'll explain each step you need to know to display records from the database using Servlets. The steps for displaying records in JSP pages and Java Beans are

Beginner: Using Servlets to display, insert and update records in database.(3)

servlet Updating records in the Database with Java Servlets. Overview : This article is next in the series of articles about selecting, inserting, updating and deleting records from the database using JDBC. In this article we will learn how to update

Beginner: Using Servlets to display, insert and update records in database.(2)

servlet Inserting records into the Database with Java Servlets. Overview : This article is next in the series of articles about selecting, inserting, updating and deleting records from the database using JDBC. In this article we will learn how to ins

Beginner with c# 4

1¡£4 Ô¤¶¨ÒåÀàÐÍ£¨Predefined types£ c#Ìá¹ÁËһϵÁÐÔ¤¶¨ÒåÀàÐÍ¡£ËüÃÇÓëc/c++Óв»ÉÙÏàËƵĵط½¡£Ô¤¶¨ÒåÒýÓÃÀàÐÍÓÐobjectºÍstring¡£ objectÀàÐÍÊÇËùÓÐÆäËûÀàÐ͵Ļù´¡¡£ Ô¤¶¨ÒåÀàÐÍ°üÀ¨·ûºÅÊý¡¢ÎÞ·ûºÅÊý¡¢¸¡µã¡¢²¼¶û¡¢×Ö·ûºÍʽøÖÆÊý¡£·ûºÅÊýÓУºsbyte¡¢short¡¢ intºÍlong£»

Beginner with c# 7

1.7 语句(Statements) c#借用了c/c++大多数的语句方法,不过仍然有些值得注意的地方.还有些地方是有所改动的. 在这里,我只提一些c#特有的东东. 1.7.10 "foreach"语句 "foreach"语句列举一个集合内的所有元素,并对这些元素执行一系列的操作.还是看看例子吧:*/ using System; using System.Collections; class Test { static void WriteList(ArrayLis

Beginner with C#

1 绪论 c# 是一种简练,时髦(?),面向对象(object oriented),类型可靠(type-safe)的 编程语言.它(发音:C sharp)是从c/c++发展而来的(?俺觉得更象是java),和c/c++ 是一个语系.所以,很容易被c/c++的程序员接受.c#的目标是结合Visual Basic的高产和 C++质朴的力量. c#将会是vs7的一分子.vs7还支持vb,vc和标记语言--VBScript和JScript.所有这些语言 都会在Next Generation Window

Beginner with c# 2

1.2 自动化的内存管理(Automatic memory management) 手动管理内存需要程序员自行分配和释放内存块.这要求程序员有清晰的头脑和对整个运行过程有十分的 把握(好难!).而c#把程序员从这难以承担的任务中解放出来.在多数的情况下,这种自动内存管理提 高代码的质量和程序员的生产力.并且,不会对程序的意图和执行产生幅面的影响(?俺可不相信m$的鬼 话).不过,估计比java的回收站好一点吧.因为c#出道迟嘛(尽胡扯).好了,来看看例子.*/ using System; pub