当前位置:网站首页>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
边栏推荐
- Openfeign timeout setting
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
- 在.NE6 WebApi中使用分布式缓存Redis
- .NET7之MiniAPI(特别篇):.NET7 Preview3
- Source Generator实战
- MAUI初体验:爽
- Laravel8- use JWT
- Opencv combines multiple pictures into video
- Xamarin效果第二十二篇之录音效果
猜你喜欢
C# WPF UI框架MahApps切换主题
Golden nine silver ten interview season, you are welcome to take away the interview questions (with detailed answer analysis)
Openfeign details show
FileNotFoundError: [Errno 2] No such file or directory
ASP. Net 6 middleware series - Custom middleware classes
Xamarin effect Chapter 21 expandable floating operation button in GIS
Laravel new route file
LNMP MySQL allows remote access
Use of slice grammar sugar in C #
Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
随机推荐
[software testing] understand the basic knowledge of software testing
Laravel new route file
Fight leetcode again (290. Word law)
SQL statement - DDL
Maui initial experience: Cool
Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
2022山东省安全员C证上岗证题库及在线模拟考试
使用栈来解决”迷你语法分析器“的问题
2022年P气瓶充装培训试题及模拟考试
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
7-11 重排链表 (25 分)
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
使用split来解决“最常见的单词”问题
使用两种方法来解决“最大回文数乘积”问题
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
C language to achieve address book - (static version)
編碼電機PID調試(速度環|比特置環|跟隨)
利用栈的回溯来解决“文件的最长绝对路径”问题
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!