Why you should give a second look at C# and .NET

C# is Awesome

Properties

public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string ProductName { get; set; }
public int ProductCategoryId { get; init; }

LINQ and var

public List<Place> places = new List<Place>();// Objects are added to the list// Lambda syntax
var placesToVisit = places.Where(p => p.Visited == false).ToList();
// Query syntax
var placesToVisit =
from p in Places
where p.Visited == false
select p;
var words = "Hello there!";// This is valid
words = "General Kenobi!";
// This is NOT valid
word = 7;

Async/Await

private readonly HttpClient _httpClient = new HttpClient();  downloadButton.Clicked += async (o, e) => {     
// This line will yield control to the UI as the request
// from the web service is happening.
//
// The UI thread is now free to perform other work.
var stringData = await _httpClient.GetStringAsync(URL);
DoSomethingWithData(stringData);
};
private DamageResult CalculateDamageDone()
{
// Code omitted:
//
// Does an expensive calculation and returns
// the result of that calculation.
}
calculateButton.Clicked += async (o, e) =>
{
// This line will yield control to the UI while
// CalculateDamageDone() performs its work. The UI thread is
// free to perform other work.
var damageResult = await Task.Run(() => CalculateDamageDone());
DisplayDamage(damageResult);
};

.NET is a Wonderful Platform

The Editors are top Notch

  • Visual Studio (Windows; IDE)
  • Visual Studio for Mac (MacOS; IDE)
  • Visual Studio Code (Windows, Mac, Linux; Text Editor)
  • Rider (Windows, Mac, Linux; IDE)

The CLI and Package Management tools are very powerful

dotnet add package <package name>

Entity Framework Makes Database Migrations a Breeze

// Model creation omittedpublic class BookstoreContext : DBContext {
public BookstoreContext() : Base() { }

public DbSet<Authors> { get; set; }
public DbSet<Books> { get; set; }

public override void OnModelCreating(
DbModelBuilder modelBuilder) {
modelBuilder.Entity<Author>()
.HasMany<Book>(a => a.Books)
.WithMany(b => b.Authors)
.Map(ab =>
{
ab.MapLeftKey("AuthorId");
ab.MapRightKey("BookId");
ab.ToTable("AuthorBook");
});
}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store