Microsoft Launches G#: A Go-Like Language for .NET

21CTO导读:A language compatible with Microsoft's .NET ecosystem and Go — G#.

Microsoft has introduced a new programming language called G#, a hybrid of the .NET and Go languages. This architectural design makes it an exceptionally flexible tool.

Microsoft has open-sourced .NET, which has not only accelerated the platform's development but also made it possible to build new languages and features on top of the .NET runtime and compiler. At the same time, the extensibility of Visual Studio Code allows developers to easily leverage the tools provided by these new platforms.

On the .NET platform, one particularly compelling new project is G#, a Go-like language. G#'s target domains include systems programming and mobile application development, aiming to deliver small, secure libraries that can be consumed by other .NET applications.

Image

G# draws on the experience of Go, Kotlin, and Swift, and leverages NuGet and other code repository services to build code on the mature .NET platform, making it compatible with .NET assemblies and libraries.

G#'s development is based on GitHub, and its team maintains a very fast release cycle.

GitHub: https://github.com/GregoriBrunoFelicio/G-Sharp

Image

Getting Started with G#

Getting started with G# is remarkably simple.

You need a supported .NET version and the corresponding SDK for your target operating system. G#-generated code is compatible with .NET 8 through .NET 10, but .NET 10 is recommended. The G# SDK and templates are available from NuGet, ensuring you can install and run G# through the .NET CLI.

The quickest way to get started is to install the G# templates, then use them to create a console application. After that, you can open the application using the development tool of your choice and start extending it. The basic application structure is very simple, containing a project file, a program .gs file, and a NuGet configuration for managing packages and libraries, with support for a local SDK — which is especially useful if you are building G# from source.

Building and running the default console template is fast, producing output in just over four seconds on an Arm-based Windows PC — a significant advantage for building and debugging large applications.

Beyond the basic console implementation, the installed templates provide options for several different types of applications and libraries. Additionally, there is a Visual Studio Code extension for G# on the Visual Studio Marketplace that can be downloaded. The extension includes the corresponding language server component, which speeds up development. The documentation provides a command-line installation option, so you can install the extension without hunting for the required files — the next time you open VS Code, you can start coding in G# right away.

Alternatively, you can use the G# language's own gsc compiler directly instead of invoking it through MSBuild in the .NET CLI. This approach is particularly useful when you need to output code targeting a specific .NET version or compile it into an assembly for use by other .NET languages. This method avoids interpreted code, allowing you to deliver pre-compiled binaries directly.

Inside the G# Language

The G# language itself is very intuitive. Code is organized in packages, with executable parts defined as funcs.

By default, G# uses the .NET System namespace, so you can use familiar structures directly without learning a different way to implement common functionality. If you don't want to import the .NET System namespace by default, you can disable the import in the compiler configuration.

Each function can accept parameters and return values, with parameter types declared in the parameter list. The parameter list can end with a return type declaration to ensure the expected data is returned. Most types include length information, such as int64, and there are also aliases for common types from other languages. The string type allows for alignment and formatting information. In addition to functions, you can define structs and classes to handle variables — structs handle values, while classes handle references. Similarly, data structs and classes allow you to treat variables as data, performing copy and assignment operations.

G#'s language constructs are mostly familiar, especially if you are accustomed to languages like Go. It offers some interesting shortcuts, such as if let for null checks when parsing function arguments. You can combine if let with G#'s exception handling mechanism to manage more complex program flows. Other features include using for in to iterate over collections, allowing you to pass and use arrays of arbitrary length within functions without determining the array length before performing operations.

Using G# in Distributed Systems

G# is designed to support asynchronous programming, which is essential for developing distributed applications.

It uses the common async and await constructs, implemented here with async func.

Interestingly, G# allows you to wrap a group of asynchronous operations in a scope, so you can run a series of operations and manage failures while preserving the results of successful operations for use elsewhere in the application.

This allows developers to associate parent and child operations, ensuring that the parent operation always returns after the child operations. You can use asynchronous sequences to handle streams, but if you prefer, you can also use the Go extension package to support Go-like channels.

Author: 聆听音乐的鱼

Reference: https://news.ycombinator.com/item?id=48871721

Related reading:

Microsoft Releases First Preview of .NET 11 and C# 15

NVIDIA Acquires Hugging Face for $12.9 Billion: Enterprise Open-Source AI Supply Chain Shifts from Distributed to Centralized

Microsoft Joins Google's Camp, Supports Go Language for AI Agent Development

Related Articles

分享網址
AINews·AI 新聞聚合平台
© 2026 AINews. All rights reserved.