当前位置:网站首页>C introduction of variable parameter params
C introduction of variable parameter params
2022-04-23 03:08:00 【Dotnet cross platform】
c# Variable parameters params Introduction to
As a netUp Lord , In today's b The station is here java A video of , Introduction of variable parameters , So today I'd like to introduce to you c# Variable parameters in params Introduction to the use of ,
Let's first look at the official explanation : Use params Keyword can specify a variable number of parameters params. The parameter type must be a one-dimensional array . In the method declaration params No other parameters are allowed after the keyword , And only one is allowed in a method declaration params keyword . If params The declaration type of the parameter is not a one-dimensional array , A compiler error occurs params. Use params When a method is called with a parameter , You can pass in :
Comma separated list of parameters of array element type .
An array of parameters of the specified type .
No parameter . If no parameters are sent , be params The length of the list is zero .
Example
static void Main(string[] args)
{
string[] lst = new string[] { " Zhang San ", " Li Si ", " Wang Wu " };
AddName(lst);
AddName(" Zhang San "," Li Si "," Wang Wu ");
}
static void AddName(params string[] args)
{
string allName= string.Join(",", args);
}
Variable parameters are used as above , When we define functions, we use keywords for arrays params, The array becomes a variable parameter , When calling, the data we pass in will form an array , When called, we can pass in no matter how many elements .
I understand the application scenarios of variable parameters , Variable parameters ( Array ) Not only can arrays be passed in , It can also be passed in the form of direct assignment of formal parameters when calling , It will still be treated as an array in the method , This is the advanced nature of variable parameters. .
Personally, I think it's just convenient before calling the method , Reduce the process of array instantiation , because up The main has hardly used variable parameters in its work , My understanding may be limited, and my friends who know can tell me more abundant usage scenarios , That's the end of today's presentation !
版权声明
本文为[Dotnet cross platform]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230301333262.html
边栏推荐
- Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
- 对.NET未来的一点感悟
- PID debugging of coding motor (speed loop | position loop | follow)
- AOT和单文件发布对程序性能的影响
- Blazor University (11) component - replace attributes of subcomponents
- Er and eer models
- The most easy to understand service container and scope of dependency injection
- Dynamic sequence table + OJ
- How does Microsoft solve the problem of multiple PC programs
- Impact of AOT and single file release on program performance
猜你喜欢

腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!

編碼電機PID調試(速度環|比特置環|跟隨)

Realize QQ login with PHP
![FileNotFoundError: [Errno 2] No such file or directory](/img/ea/0c3f2768d14c1f4bb42bd1309ab996.png)
FileNotFoundError: [Errno 2] No such file or directory

2022T电梯修理考试模拟100题及在线模拟考试

C#中切片语法糖的使用

Use of slice grammar sugar in C #

The backtracking of stack is used to solve the problem of "the longest absolute path of file"

Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)

How to write the expected salary on your resume to double your salary during the interview?
随机推荐
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
Response processing of openfeign
A set of C interview questions about memory alignment. Many people make mistakes!
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)
2022G2电站锅炉司炉考试题库及在线模拟考试
. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
2022年度Top9的任务管理系统
[software testing] understand the basic knowledge of software testing
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
LNMP MySQL allows remote access
OLED multi-level menu record
OLED多级菜单记录
宁德时代地位不保?
【鉴权/授权】自定义一个身份认证Handler
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
Openfeign details show
交换二叉树中每个结点的左和右
数据挖掘系列(3)_Excel的数据挖掘插件_估计分析
队列的存储和循环队列