-
C# 阵列——C#中的 GetValue()方法,带示例| Set–2
阵列。C# 中的 GetValue()方法,带示例| Set–2
原文:https://www . geesforgeks . org/array-getvalue-method-in-csharp-with-examples-set-2/
数组。C# 中的 GetValue()方法用于获取当前数组中指定元素的值。本法过载列表共 8 法,如下:
阵。GetValue(Int32,Int32) 数组。GetValue(Int64,Int64) 数组。GetValue(Int32) 数组。GetValue(Int64) 数组。GetValue(Int32,Int32,Int32) 数组。GetValue(Int64,Int64,Int64) GetValue(Int32[]) GetValue(Int64[])
下面,我们来讲解一下数组。GetValue(Int32) 和数组。GetValue(Int64)方法。
GetValue(Int32) 方法用于获取一维数组中指定位置的值。索引被指定为 32 位整数。
语法:
public object GetValue (int index);
这里,索引是表示要获取的数组元素位置的 32 位整数。
返回:该方法返回对象类型的一维数组中指定位置的值。
异常:
- 参数异常:如果当前数组没有恰好一维。
- indexoutofrangerexception:如果索引在当前数组的有效索引范围之外。
GetValue(Int64) 方法用于获取一维数组中指定位置的值。索引被指定为 64 位整数。
语法:
public object GetValue (long index);
这里,索引是表示要获取的数组元素位置的 64 位整数。
返回:该方法返回对象类型的一维数组中指定位置的值。
异常:
- 参数异常:如果当前数组没有恰好一维。
- indexoutofrangerexception:如果索引在当前数组的有效索引范围之外。
例 1:
// C# program to demonstrate the
// Array.GetValue(Int32) Method
using System;
public class GFG {
public static void Main()
{
// declare a character array
char[] arr = new char[]{'A', 'B', 'C', 'D'};
// use of GetValue(Int32) Method
Console.WriteLine("element at index 3 is : " + arr.GetValue(3));
Console.WriteLine("element at index 1 is : " + arr.GetValue(1));
Console.WriteLine("element at index 2 is : " + arr.GetValue(2));
Console.WriteLine("element at index 0 is : " + arr.GetValue(0));
}
}
输出:
element at index 3 is : D
element at index 1 is : B
element at index 2 is : C
element at index 0 is : A
例 2:
// C# program to demonstrate the
// Array.GetValue(Int64) Method
using System;
public class GFG {
public static void Main()
{
// declare a string array
string[] arr = new string[5];
// use "SetValue()" method to set
// the value at specified index
arr.SetValue( "C++", 0 );
arr.SetValue( "Java", 1 );
arr.SetValue( "C#", 2 );
arr.SetValue( "Perl", 3 );
arr.SetValue( "Python", 4 );
// Using GetValue(Int32) Method
Console.WriteLine("element at index 3 is : " + arr.GetValue(3));
Console.WriteLine("element at index 1 is : " + arr.GetValue(1));
Console.WriteLine("element at index 2 is : " + arr.GetValue(2));
Console.WriteLine("element at index 0 is : " + arr.GetValue(0));
Console.WriteLine("element at index 0 is : " + arr.GetValue(4));
}
}
输出:
element at index 3 is : Perl
element at index 1 is : Java
element at index 2 is : C#
element at index 0 is : C++
element at index 0 is : Python
注意:对于在线编译器,不能使用 32 位或 64 位整数。对 32 或 64 位整数使用脱机编译器。
版权属于:月萌API www.moonapi.com,转载请注明出处
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式