Skip to content

Repository files navigation

G# logo

G#

A modern, simple, and accessible programming language for .NET.

Kotlin- and Swift-style semantics, Go- and Python-inspired syntax — on the CLR you already know.

build quality dashboard NuGet license: MIT

Documentation · A Tour of G# · Getting started · Editor support · Contributing


package hello

import System

data class Point(X int32, Y int32)

func describe(p Point?) string {
    if let q = p {
        return "point at (${q.X}, ${q.Y})"
    }
    return "nowhere"
}

let origin = Point(0, 0)
let moved = origin with { X = 3 }

Console.WriteLine(describe(moved))       // point at (3, 0)
Console.WriteLine(moved == Point(3, 0))  // True — structural equality
Console.WriteLine(describe(nil))         // nowhere

Every sample in this README compiles and runs with the current compiler.

Why G#?

  • Small, predictable syntax. Type-after-name declarations, no semicolons, no ceremony. Top-level statements are the entry point; a one-file program is a real program.
  • Null safety by design. T? is a distinct type. if let, guard let, while let, ?., and ?? make the absent case explicit — the compiler won't let you forget it.
  • Data modeling that pulls its weight. data class / data struct give you structural equality, with-copy, and deconstruction from a single line.
  • Structured concurrency. chan, go, and scope { } blocks bring Go-style channels and goroutine-shaped tasks to .NET, with child work joined and failures observed before control leaves the scope.
  • The whole .NET ecosystem. Every BCL type, every NuGet package, LINQ, P/Invoke, events — callable directly, no bindings or wrappers. G# assemblies are ordinary .NET assemblies consumable from C# and F#.
  • First-class tooling. An MSBuild SDK (dotnet build/run/pack just work), a language server with VS Code and Visual Studio extensions, a REPL, code analyzers, and a C#→G# migration tool.

Getting started

You need the .NET 10 SDK. Then:

dotnet new install Gsharp.Templates
dotnet new gsharp-console -n MyApp
cd MyApp && dotnet run
# Hello from GSharp!

A .gsproj is a regular SDK-style .NET project that happens to compile .gs files:

<Project Sdk="Gsharp.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <RootNamespace>MyApp</RootNamespace>
  </PropertyGroup>
</Project>

Templates for libraries, xUnit test projects, and web apps ship in the same package: gsharp-lib, gsharp-xunit, gsharp-web.

A taste of G#

Channels and structured concurrency

package pipeline

import System
import Gsharp.Extensions.Go

func produce(ch chan int32) int32 {
    for var n = 1; n <= 3; n = n + 1 {
        ch <- n * 10
    }
    return 0
}

let ch = make(chan int32, 3)

scope {
    go produce(ch)

    for var i = 0; i < 3; i = i + 1 {
        Console.WriteLine("got ${<-ch}")
    }
}

Console.WriteLine("pipeline drained")

scope { } guarantees the goroutines it spawns finish (and surface their failures) before the block exits. See the concurrency guide for select-style patterns, buffered channels, and close semantics.

Seamless .NET interop

package interop

import System
import System.Collections.Generic
import System.Linq

let nums = List[int32]()
nums.Add(1)
nums.Add(2)
nums.Add(3)

let doubled = nums.Select((x int32) -> x * 2).Sum()
Console.WriteLine("sum of doubles: $doubled")   // 12

CLR generics use G#'s bracket spelling (List[int32]), lambdas flow into LINQ, and @DllImport functions bind as P/Invoke stubs. The full story — events, delegates, ref/out, function pointers, struct marshalling — is in the CLR interop reference.

Want more? The Tour of G# walks through pattern matching, interfaces, extension functions, error handling, generics, and the rest of the language.

Editor support

VS Code

gsharplang.vscode-gsharp — syntax highlighting, completion, hover, diagnostics, formatting, build/run commands, and debugging. code --install-extension gsharplang.vscode-gsharp

Visual Studio

The G# extension for Visual Studio 2022/2026 adds native projects, NuGet, managed debugging, Test Explorer, templates, and six G# themes on top of the same language server.

REPL

dotnet tool install --global Gsharp.Repl gives you gsi, an interactive REPL and .gs file runner.

Tooling

Tool What it does
Gsharp.NET.Sdk MSBuild SDK — dotnet build, run, test, and pack for .gsproj projects, including Roslyn source-generator hosting and code analyzers.
Gsharp.Templates dotnet new templates: console, library, xUnit, web.
Gsharp.Repl gsi — interactive REPL and file runner.
Gsharp.Cs2Gs cs2gs — migrates C# projects to G#, including Roslyn analyzers and their tests.

cs2gs doubles as the compiler's quality gate: every C# syntax construct is classified in a machine-checked coverage inventory, a per-construct conformance corpus is translated, compiled, IL-verified, and byte-compared against its C# baseline on every PR, and newly discovered gaps are automatically filed as issues (see tools/cs2gs/README.md).

Documentation

The documentation site hosts the language tour, tutorials, the language guide, the specification, and the tooling reference; its source lives in website/. Design history is recorded as Architecture Decision Records.

Repository layout

src/
  Core/               # Compiler front-end: syntax, binder, lowering, symbols, emit
  Compiler/           # gsc — command-line compiler driver
  Repl/               # gsi — interactive REPL
  LanguageServer/     # LSP server backing the editor experience
  Sdk/                # MSBuild SDK, templates, and Gsharp.Extensions
  vs-gsharp/          # Visual Studio extension
tools/cs2gs/          # C# → G# migration tool and conformance corpus
e2etests/             # End-to-end smoke tests
test/                 # xUnit suites covering the compiler, SDK, and tooling
website/              # Docusaurus documentation site

Contributing

Contributions are welcome — read CONTRIBUTING.md for build, test, and pull-request guidance. Compatibility commitments are documented in docs/compatibility-and-stability.md, and vulnerabilities can be reported privately through SECURITY.md.

License

G# is open source under the MIT license.

About

GSharp Programming Language

Topics

Resources

Contributing

Security policy

Stars

463 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages