zoukankan      html  css  js  c++  java
  • 命名参数 named parameter

    C#4.0引入了命名参数,它允许指定要使用哪个参数。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace NamedPara
    {
        public static class WordProcessor
        {
            private const bool defaultval = false;
    
            public static List<string> GetWords(
                string sentence,
                bool capitalizwwords = false,
                bool reverseorder = defaultval,
                bool reverseWords = false
                )
            {
                List<string> words = new List<string>(sentence.Split(' '));
    
                return words;
            }
            
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                string sentence = "can be assigned the values true false or null.";
                List<string> words;
    
                words = WordProcessor.GetWords(sentence);
                foreach (string s in words)
                {
                    Console.Write(s);
                    Console.Write(" ");
                }
                Console.Write("
    ");
    
                words = WordProcessor.GetWords(sentence, reverseWords: true, capitalizwwords:true);
    
                foreach (string s in words)
                {
                    Console.Write(s);
                    Console.Write(" ");
                }
                Console.Write("
    ");
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    设置开发环境
    安装开发软件
    学习路线
    预备知识
    Spring是什么
    yum安装nginx
    .net 哈希
    Excel文件处理Demo
    汉字处理组件
    Log4Net
  • 原文地址:https://www.cnblogs.com/zzunstu/p/3405034.html
Copyright © 2011-2022 走看看