在c#中循环数组 [英] Looping in array in c#
本文介绍了在c#中循环数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是asp.net和c#的新手。现在我想在c#中循环遍历数组。你能举个例子吗?在此先感谢
Hi, i am very new to asp.net and c#. Now i want to loop through the array in c#. can you give me a example. Thanks in advance
推荐答案
请参阅MSDN上的文档:
ForEach:
http://msdn.microsoft.com/en-us/ library / 2h3zzhdw.aspx [ ^ ]
Linq:
http://msdn.microsoft.com/en-us/library/zecdkyw2(v = vs.110)的.aspx [ ^ ]
Refer to documentation on MSDN:
ForEach:
http://msdn.microsoft.com/en-us/library/2h3zzhdw.aspx[^]
Linq:
http://msdn.microsoft.com/en-us/library/zecdkyw2(v=vs.110).aspx[^]
如果您不知道如何编写一个访问数组中每个值的简单循环,我相信您在C#编程方面处于基础零点,更不用说使用ASP了.NET。
没有错误处于地面零点;我们都从那里开始了:)而且,好消息是:如果你现在就开始,在一两个星期内你再也不会认为你对C#是新的了。
我已经多次在这里发布了我认为在C#.NET中开发基本能力的好资源(一些免费):[ ^ ]。
我鼓励您首先专注于掌握C# .NET编程的基本要素;有一些你需要学习的东西,几乎所有的编程语言都是常见的。
我会担心如果你不是从C#的基础开始然后继续前进到复杂的ASP.NET世界将是非常困难的。
要点(imho):
在.NET C#中创建更高级别的对象:这些将是NameSpace,Class(静态和非静态),Struct,Enum
范围,表示如何管理您创建的不同对象的名称在编译/执行代码的任何给定时刻进行评估
Flow-Of -Control:循环:for,foreach,while,do。如果/ Else和Switch / Case结构。
了解.NET类型:值类型,引用类型;理解类型转换。
变量(在.NET'字段中)如何声明它们,控制它们的可访问性(范围)。
属性
方法(静态和非静态):传递参数,返回结果。通过值传递,使用'out和'ref传递。
简单数学运算符。运算符优先级。
布尔比较。理解'null,string.IsEmpty等的使用
基本数据结构:数组,通用列表。
If you do not know how to write a simple loop that accesses each value in an Array, I believe you are at ground-zero in terms of programming in C#, let alone using ASP.NET.
There's nothing wrong with being at "ground-zero;" we all start there :) And, the good thing is: if you start now, within a week or two you will never think you are "new" to C# again.
I've posted several times here on what I think are good resources (some free) for developing a basic competency in C# .NET: [^].
I encourage you to focus your study on first mastering the essential elements of C# .NET programming; there are certain things you need to learn which are common to almost all programming languages.
I would be concerned that if you do not start with a "foundation" in C# then moving on to the complex world of ASP.NET is going to be very difficult.
Essentials (imho):
Creating "Higher-Level Objects:" in .NET C# those would be NameSpace, Class (static and non-static), Struct, Enum
"Scope" which means how to manage how the names of different objects you have created are evaluated at any given moment in the compilation/execution of your code
Flow-Of-Control: Loops: for, foreach, while, do. If/Else and Switch/Case structures.
Understanding .NET Types: Value Types, Reference Types; understanding Type conversion.
Variables (in .NET 'Fields) how to declare them, control their accessibility (scope).
Properties
Methods (static and non-static): passing parameters, returning results. passing by value, passing using 'out and 'ref.
Simple Math operators. operator precedence.
Boolean comparison. understanding use of 'null, string.IsEmpty, etc.
Basic Data Structures: Arrays, Generic Lists.
你好neethu ..你问题的答案是......
参考循环数组
Hi neethu..here is the answer for your question..
ReferLoop through array
int[] nums = {
72,
52,
63,
852,
421,
86
};
lbl_dispaly.Text = "Numbers <br />";
foreach (int num in nums)
{
lbl_dispaly.Text += num.ToString() + "<br />";
}
这篇关于在c#中循环数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文