C#4.o 特性

using System;

namespace C4特性
{
    public class FeatureOne
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }

    class Program
    {
        //dynamic
        public static void DemoOne()
        {
            //在c#中使用js动态语言的特性,前提是将一个变量声明为FeatureOne类型。
            dynamic o = new FeatureOne { Key = "key1", Value = "value1" };
            Console.WriteLine(string.Format("demo key is {0} and value is {1}", o.Key, o.Value));
            Console.ReadLine();
        }

        //可选参数
        //value1默认值为value1  value2默认值为value2   调用时如果没有传此参数  则使用默认值
        public static void DemoTwo(string name, string value1 = "value1", string value2 = "value2")
        {
            Console.WriteLine(string.Format("demo key is {0} and value1 is {1} and value2 is {2}", name, value1,value2));
            Console.ReadLine();
            
        }

        //重载了方法DemoTwo  如果有个和可选参数方法某个参数相同的方法签名的方法时会优先执行没有可选参数的方法
        public static void DemoTwo(string name, string value)
        {
            Console.WriteLine(string.Format("demo key is {0} and value is {1}", name, value));
            Console.ReadLine();

        }

        //命名参数
        public static void DemoThree(int id, string content)
        {
            Console.WriteLine(string.Format("demo key is {0} and value1 is {1}", id, content));
            Console.ReadLine();

        }

        static void Main(string[] args)
        {
            //DemoOne();

            //DemoTwo("it's");
            //DemoTwo("it's","it's value");
            //DemoTwo("it's","who");

            //调用时参数名字需要与方法中的参数名字一致  id content
            DemoThree(id: 1, content: "i am conten");
        }
    }
}

 

转载于:https://www.cnblogs.com/sidihu/archive/2012/11/03/2752109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值