private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private bool _isGreat;
public bool IsGreat
{
get { return _isGreat; }
set { _isGreat = value; }
}
public string Name { get; set; }
public bool IsGreat { get; set; }
private string _name = "C# 6.0";
public string Name
{
get { return _name; }
set { _name = value; }
}
private string _isGreat = true;
public bool IsGreat
{
get { return _isGreat; }
set { _isGreat = value; }
}
public string Name { get; set; } = "C# 6.0";
public bool IsGreat { get; set; } = true;
public string Name { get; } = "C# 6.0";
public bool IsGreat { get; } = true;
var query = String.Format("{{ UserId: ObjectId(\"{0}\") , Name: \"{1}\" }}", UserId, Name);
var cursor = await locationCollection.FindAsync(query);
var query = $"{{ UserId: ObjectId(\"{UserId}\") , Name: \"{Name}\" }}";
var cursor = await locationCollection.FindAsync(query);
Console.WriteLine($"Getting from {uri.AbsoluteUri} took {req.GetElapsed()}s");
using System.Console;
namespace MyConsoleApp
{
class Program
{
static void Main(string [] args)
{
Console.WriteLine("Starting process");
}
}
}
using static System.Console;
namespace MyConsoleApp
{
class Program
{
static void Main(string [] args)
{
WriteLine("Starting process");
}
}
}
using ReallyLongNamespaceThatMakesItLessReadable;
namespace MyConsoleApp
{
class Program
{
static void Main(string [] args)
{
ReallyLongNamespaceThatMakesItLessReadable.Log("Failed writing to file!");
}
}
}
using static ReallyLongNamespaceThatMakesItLessReadable;
namespace MyConsoleApp
{
class Program
{
static void Main(string [] args)
{
Log("Failed writing to file!");
}
}
}
int count = (list == null) ? 0 : list.Count();
int count = list?.Count() ?? 0;
Address address = locations?.FirstOrDefault(loc => loc.UserId == UserId)?.Address;
try
{
// code
}
catch (HttpException ex)
{
if (ex.GetHttpCode() == 404)
{
Exec404Handler();
}
else if (ex.GetHttpCode() == 500)
{
Exec500Handler();
}
}
try
{
// code
}
catch (HttpException ex) where (ex.GetHttpCode() == 404)
{
Exec404Handler();
}
catch (HttpException ex) where (ex.GetHttpCode() == 500)
{
Exec500Handler();
}
try
{
// code
}
catch (HttpException ex) where (Log(ex))
{
// doesn't execute if Log returns false
}
var cities = locations.Select(location => location.City).Distinct();
private Guid _userId = Guid.NewGuid();
public Guid UserId { get { return _userId; } }
public string GroupName { get; set; }
public UserKey Key
{
get {
return new UserKey(UserId, GroupName)
}
}
public Guid UserId { get; } = Guid.NewGuid();
public string GroupName { get; set; }
public UserKey Key => new UserKey(UserId, GroupName); // no get!
public string FormatAddress(string address, string city, string state)
{
return address + " " + city + ", " + state;
}
public string FormatAddress(string address, string city, string state)
=> address + " " + city + ", " + state;
The use of C#6 requires Visual Studio 2015! If you are sharing code with other people who are not using Visual Studio 2015, they won't be able to compile the code.
In addition to open sourcing a lot of their tech infrastructure, Microsoft has improved their documentation, including .NET and Roslyn.