{C#} C#6酷酷的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrammaOfCS6
{
    class Functions
    {
       public DateTime InitTime { get; } = DateTime.Now;

       public string TypeOfIt => string.Format("{0}", typeof(Functions));

       public int GetMax(int left, int right) => Math.Max(left, right);

       public int GetMin(int left, int right) => Math.Min(left, right);

       public string GetFirstName(string fullname)
       {
           return fullname?.Split(' ')[0];
       }

       public int? GetNameLength(string name)
       {
           return name?.Length;
       }

       public float AddNumber(float x, float y, Func<float, float, float> acc)
       {
           return acc?.Invoke(x, y) ?? (x + y);
       }

       public void PrintParam(string first, string second)
       {
           Console.WriteLine(string.Format("{0}:{1},{2}:{3}", nameof(first), first, nameof(second), second));
       }

       public void Introduce()
       {
           Console.WriteLine("you are calling {0}.{1}", nameof(Functions), nameof(Introduce));
       }

       public void WriteCMain()
       {
           var world = "world";
           var hello = $"hello, {world}";

           var cppHelloWorldProgram = new Dictionary<int, string>
           {
               [10] = $"{HeadOfCMain()}",
               [20] = "    printf(\"hello, world\")",
               [30] = "    return 0;}"
           };


           Console.WriteLine(cppHelloWorldProgram[10]);
           Console.WriteLine(cppHelloWorldProgram[20]);
           Console.WriteLine(cppHelloWorldProgram[30]);
       }

       private string HeadOfCMain()
       {
           return "int main() {";
       }
   }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容