C#
Beginner
1 min read
Creating and Running a .NET 8 Console Project
Example
// Sample .csproj for a .NET 8 console application
/*
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
*/
// Program.cs — top-level statements entry point
using System.Text.Json;
// Implicit usings (enabled in csproj) auto-import common namespaces:
// System, System.Collections.Generic, System.IO, System.Linq, etc.
var person = new { Name = "Alice", Age = 30 };
// Serialize to JSON using System.Text.Json (built-in, no NuGet needed)
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions
{
WriteIndented = true
});
Console.WriteLine(json);
// Deserialize back to a dynamic object
var restored = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json);
if (restored is not null)
{
Console.WriteLine($"Name: {restored["Name"].GetString()}");
Console.WriteLine($"Age: {restored["Age"].GetInt32()}");
}