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();
            }
        }
    }
  • 相关阅读:
    设计模式第一次练习
    区间最大数
    魔方数
    螺旋数
    回文串
    最长单词
    指针的应用之学生成绩
    赛马
    突击队任务
    贪婪之骑士
  • 原文地址:https://www.cnblogs.com/zzunstu/p/3405034.html
Copyright © 2011-2022 走看看