zoukankan      html  css  js  c++  java
  • C# 新语法收集

    内联变量

    使用int.tryparst时,先要申明变量,用于out参数

    int d;

    int.tryparse(s,out d);

    使用内联变量写法可以如下.功能一样简化了写化

    int.tryparse(s,out int d)

    $"{val1}-{val2}"

    作用如同string.format("{0}-{1}",val1,val2) , $开头的字符串中的{}内将当做变量解析.

    方法内写方法

    可以在方法内部写一些方法.类似JS的这种在函数中写一个函数

      function showmsg(msg)

           {

        function validate(){}

      }

    /*

    比如处理一个数字字符串排序,如果只是临时用一下,可以不必再加个方法,直接在方法内写个处理方法就行了

    */

      // 将一个数字组成的串排序

      private string orderlist(string strnum)

      {

      }

      // 给定字符串,返回排序后结果

      public string orderstringnum(string str,int ordertype)

      {

        return this.orderlist(str);

      }

    // 直接写在方法内

      // 给定字符串,返回排序后结果

      public string orderstringnum(string str,int ordertype)

      {

        string orderlist(string strnum)

        {

        }

        return orderlist(str);

      }

    // 注意事项:方法前面不能加private public之类,它只能在声明方法内部使用.和LAMBDA的作用相似,但是它本质是个方法,并不会像LAMBDA那样写起来别扭.

  • 相关阅读:
    SQL2008性能计数器注册表配置单元一致性失败
    win8 下 IIS APPPOOLDefaultAppPool 登录失败的解决方法
    Win8 x64环境下VS2010 C#工程运行报错:没有注册类 (异常来自 HRESULT:0x80040154
    编辑距离
    UVA 147 Dp(完全背包)
    poj 1141 Brackets Sequence
    hdu2612 Find a way BFS
    I
    javascript--运算符
    javascript--变量
  • 原文地址:https://www.cnblogs.com/mirrortom/p/9249941.html
Copyright © 2011-2022 走看看