我是靠谱客的博主 难过小松鼠,最近开发中收集的这篇文章主要介绍data.add方法c#_清单 .Add()方法与C#中的示例,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

data.add方法c#

C#List <T> .Add()方法 (C# List<T>.Add() Method)

List<T>.Add() method is used to add the object/element at the end of the list.

List <T> .Add()方法用于将对象/元素添加到列表的末尾。

Syntax:

句法:


void List<T>.Add(T item);

Parameter: It accepts single an item of T type to add in the List.

参数:它接受单个T类型的项添加到列表中。

Return value: It returns nothing – it's return type is void

返回值:不返回任何内容–返回类型为void

Example:

例:


int list declaration:
List<int> a = new List<int>();
adding elements:
a.Add(10);
a.Add(20);
a.Add(30);
a.Add(40);
a.Add(50);
Output:
10 20 30 40 50

使用List <T> .Add()方法将项目添加到列表的C#示例 (C# Example to add items to the list using List<T>.Add() Method)

using System;
using System.Text;
using System.Collections.Generic;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//integer list
List<int> a = new List<int>();
//adding elements
a.Add(10);
a.Add(20);
a.Add(30);
a.Add(40);
a.Add(50);
//printing elements
Console.WriteLine("list elements are...");
foreach(int item in a)
{
Console.Write(item + " ");
}
Console.WriteLine();
//string list
List<string> b = new List<string>();
//adding elements
b.Add("Manju");
b.Add("Amit");
b.Add("Abhi");
b.Add("Radib");
b.Add("Prem");
//printing elements
Console.WriteLine("list elements are...");
foreach (string item in b)
{
Console.Write(item + " ");
}
Console.WriteLine();
//hit ENTER to exit
Console.ReadLine();
}
}
}

Output

输出量

list elements are...
10 20 30 40 50
list elements are...
Manju Amit Abhi Radib Prem

翻译自: https://www.includehelp.com/dot-net/list-t-add-method-with-example-in-c-sharp.aspx

data.add方法c#

最后

以上就是难过小松鼠为你收集整理的data.add方法c#_清单 .Add()方法与C#中的示例的全部内容,希望文章能够帮你解决data.add方法c#_清单 .Add()方法与C#中的示例所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部