Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Visual Studio 14 CTP2 C# notes
using System;
// Using static
using System.Diagnostics.Debug;
using System.Math;
using System.Linq.Enumerable;
using System.Collections.Generic;
#if NETFX_CORE
using Windows.Web.Http;
#else
using System.Net.Http;
#endif
namespace HubApp1
{
// Primary constructors
class Class1(int x, int y, long l)
{
// Initializers for auto-properties
// Parameters on classes and structs
public int X { get; set; } = x;
public int Y { get; } = y;
// Field parameters
private long _l = l;
// Explicit constructors
public Class1() : this(1, 2, 3L) { }
public async void DoStuff()
{
WriteLine(Sqrt(3 * 3 + 4 * 4));
// Declaration expressions
if (int.TryParse("69", out int i))
{
WriteLine(i);
// Extension methods
IEnumerable<int> range = Range(5, 17);
}
HttpClient hc = new HttpClient();
try
{
throw new ArgumentNullException("X");
}
// Exception filters
catch (ArgumentNullException e) if (e.ParamName == "X")
{
WriteLine(e);
// Await in catch and finally blocks
string result = await hc.GetStringAsync(new Uri("http://bing.com"));
}
finally
{
string result2 = await hc.GetStringAsync(new Uri("http://microsoft.com"));
}
// Null propagation
string ss = null;
int? ssLength = ss?.Length;
// not yet done
// String interpolation
//string full = $"First: {x} Second: {y}";
// Binary literals and digit separators
//var bits = 0b00101110;
//var bits = 0b0010_1110;
//var hex = 0x00_2E;
//var dec = 1_234_567_890;
// Constructor Inference
//Tuple<int, string, bool> tuple = new Tuple(3, "three", true);
}
}
// Base initializer
class Class2() : Class1(4, 5, 6L) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment