C# 6.0 (VS2015 CTP6)

/*
C# 6.0 demo
https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14
*/
 
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using static System.Console;  //C# 6.0: Using static members
using static System.Math; //C# 6.0: Using static members
using static ConsoleApplication1.MyClass; //C# 6.0: Using static members
using static ConsoleApplication1.MyStruct; //C# 6.0: Using static members
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteLine("C# 6.0 Demo"); //C# 6.0: Using static members
            WriteLine(RefUrl); //C# 6.0: Using static members
 
            var dictionary = new JObject {["x"] = 3 }; //C# 6.0: Dictionary initializer
            WriteLine("dictionary[\"x\"]: {0}", dictionary["x"]);
 
            var myClass = new MyClass();
            PrintMyClass(myClass);  //C# 6.0: Using static members
            myClass.X = 100;
            PrintMyClass(myClass);
 
            var anotherDist = myClass.AnotherMyClass?.Dist; //C# 6.0: Null propagation
            WriteLine("myClass.AnotherMyClass?.Dist: {0}", anotherDist);
            // anotherDist == null
            //true
            //anotherDist > 0
            //false
            //anotherDist == 0
            //false
            //anotherDist < 0
            //false
            //anotherDist = 0
            //0
            //anotherDist
            //0
            myClass.AnotherMyClass = new MyClass(y: 0);
            anotherDist = myClass.AnotherMyClass?.Dist;
            WriteLine("myClass.AnotherMyClass?.Dist: {0}", anotherDist);
 
            string s = nameof(Console.Write); //C# 6.0: nameof operator
            WriteLine("nameof(Console.Write) = {0}", s);
 
            var p = new {Name = "Bob", Age = 30};
            WriteLine($"{p.Name} is {p.Age - 10} years old."); //C# 6.0: String interpolation
 
            try
            {
                throw new Exception("hi!");
                throw new Exception("wah!");
            }
            catch (Exception e) when (e.Message == "hi!") //C# 6.0: Exception filters
            {
                WriteLine("Catch a message is \"hi!\" exception. ");
            }
            catch (Exception e)
            {
                WriteLine("Catch other message exception. Message is \"{0}\"", e.Message);
            }
 
 
            Write("Press any key to EXIT...");
            ReadKey(true);
        }
    }
 
     
    public struct MyStruct
    {
        public static string RefUrl = "https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14";
    }
 
 
    public class MyClass
    {
        public int X { get; set; } = 90; //C# 6.0: Auto-property initializers
 
        public int Y { get; } = 100; //C# 6.0: Getter-only auto-properties
 
        public MyClass(int y)
            :this()
        {
            Y = y; //C# 6.0: Ctor assignment to getter-only autoprops
        }
 
        public MyClass()
        {
             
        }
 
        public double Dist => Sqrt(X * X + Y * Y); //C# 6.0: Expression-bodied members
 
        public MyClass AnotherMyClass { get; set; }
 
        public static void PrintMyClass(MyClass myClass)
        {
            WriteLine($"PrintMyClass: X = {myClass.X}, Y = {myClass.Y}, Dist = sqrt(x*x+y*y) = {myClass.Dist}");
        }
    }
 
}

 

结果:

C# 6.0 Demo
https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14
dictionary["x"]: 3
PrintMyClass: X = 90, Y = 100, Dist = sqrt(x*x+y*y) = 134.536240470737
PrintMyClass: X = 100, Y = 100, Dist = sqrt(x*x+y*y) = 141.42135623731
myClass.AnotherMyClass?.Dist:
myClass.AnotherMyClass?.Dist: 90
nameof(Console.Write) = Write
Bob is 20 years old.
Catch a message is "hi!" exception.
Press any key to EXIT...

 

转载于:https://www.cnblogs.com/Bob-wei/p/4515045.html

OpenQuant内盘期货插件 ## 目的 将OpenQuant与国内的CTP进行对接,让OpenQuant直接能交易国内期货 ## 设计思路 1. 利用了本开源项目的C-CTP接口,与CSharp-CTP接口 2. C-CTP、CSharp-CTP都以dll方式调用 3. 本插件同时支持QuantDeveloper、OpenQuant2和OpenQuant3(以下分别简称QD、OQ2和OQ3),只要进行再编译即可 4. 为了支持查询合约列表功能,不使用OpenQuant接口,而是使用更底层的SmartQuant接口 ## 如何安装使用 1. 找到SmartQuant接口插件目录C:\Program Files\SmartQuant Ltd\OpenQuant\Framework\bin\ 2. 复制QuantBox.OQ.CTP.dll这个SQ插件,确保此插件的版本正确 3. 找到OpenQuant接口插件目录C:\Program Files\SmartQuant Ltd\OpenQuant\Bin\ 4. 复制thostmduserapi.dll、thosttraderapi.dll两个CTP的dll到此目录 5. 复制QuantBox.C2CTP.dll、QuantBox.CSharp2CTP.dll、QuantBox.Helper.CTP.dll、NLog.dll到此目录 6. 复制CTP.nlog到此目录,或自己修改此文件 7. 找到软件的插件配置文件C:\Documents and Settings\Administrator\Application Data\SmartQuant Ltd\OpenQuant\Framework\ini\framework.xml 8. 添加``到对应位置 9. 如何使用请查看插件的使用说明 ## 如何开发 1. 确保你的C-CTP接口的dll、CSharp-CTP接口等都是最新的 3. 修改引用中有关SmartQuant类库的地址,使用你目标OQ中下的dll 4. 修改.NET框架要使用的版本,QD使用2.0,OQ2使用3.5,OQ3使用4.0 5. 修改dll生成的目录,具体请参考如何安装。 6. 调试只能使用附加到进程,建议学习并使用远程调试 7. 如果插件完全无法加载,请找到对应的log文件,查看日志。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值