with one click
csharp
// Google's official C# style guide. Covers naming conventions, formatting, LINQ, async/await, XML documentation, and .NET best practices.
// Google's official C# style guide. Covers naming conventions, formatting, LINQ, async/await, XML documentation, and .NET best practices.
Complete collection of Google's official style guides for 17 languages. Includes TypeScript, JavaScript, Python, Java, Go, C++, C#, Swift, Objective-C, HTML/CSS, AngularJS, Shell, R, Common Lisp, Vim Script, JSON, and Markdown. Production-ready coding standards used across Google's engineering organization, formatted for AI agent consumption.
Google's official AngularJS style guide. Covers controllers, services, directives, modules, dependency injection, and AngularJS 1.x best practices.
Google's official Common Lisp style guide. Covers naming conventions, formatting, macros, packages, documentation strings, and Lisp best practices.
Google's official C++ style guide. Covers headers, naming conventions, formatting, classes, memory management, RAII, smart pointers, and modern C++ features.
Google's official Go style guide. Covers gofmt formatting, naming conventions, error handling, interfaces, concurrency patterns, and package organization. Enforces idiomatic Go code with short variable names and explicit error checks.
Google's official HTML/CSS style guide. Covers formatting, naming, semantics, accessibility, and best practices for web markup and styling.
| name | csharp |
| description | Google's official C# style guide. Covers naming conventions, formatting, LINQ, async/await, XML documentation, and .NET best practices. |
Official Google C# coding standards for consistent, maintainable .NET code.
var when type is obvious from right side| Element | Convention | Example |
|---|---|---|
| Classes/Interfaces | PascalCase | UserService, IRepository |
| Methods | PascalCase | GetUserById |
| Properties | PascalCase | UserCount |
| Local variables | camelCase | userCount |
| Constants | PascalCase | MaxRetries |
| Private fields | _camelCase | _userId |
| Parameters | camelCase | userId |
| Enums | PascalCase | Direction |
// ✓ CORRECT - use var when type is obvious
var users = new List<User>();
var count = users.Count;
// ✓ CORRECT - explicit type when not obvious
IEnumerable<User> result = GetUsers();
// ✓ CORRECT - nullable reference types (C# 8+)
string? optionalName = null;
string requiredName = "Alice";
// ✓ CORRECT - auto-properties
public string Name { get; set; }
public int Count { get; private set; }
// ✓ CORRECT - private fields with underscore prefix
private readonly string _connectionString;
private int _retryCount;
// ✓ CORRECT - expression-bodied property
public string FullName => $"{FirstName} {LastName}";
// ✓ CORRECT - expression-bodied method
public string GetDisplayName() => $"{FirstName} {LastName}";
// ✓ CORRECT - traditional method body
public async Task<User> GetUserAsync(int id)
{
var user = await _repository.FindAsync(id);
return user ?? throw new NotFoundException(id);
}
// ✓ CORRECT - async all the way
public async Task<IEnumerable<User>> GetActiveUsersAsync()
{
return await _db.Users
.Where(u => u.IsActive)
.ToListAsync();
}
// ✓ CORRECT - ConfigureAwait in library code
var result = await SomeAsyncMethod().ConfigureAwait(false);
// ✗ INCORRECT - blocking on async code
var result = SomeAsyncMethod().Result; // can deadlock
// ✓ CORRECT - LINQ for queries
var activeUsers = users
.Where(u => u.IsActive)
.OrderBy(u => u.LastName)
.Select(u => new UserDto(u.Id, u.Name))
.ToList();
// ✓ CORRECT - query syntax for complex joins
var result = from u in users
join r in roles on u.RoleId equals r.Id
where u.IsActive
select new { u.Name, r.Title };
// ✓ CORRECT - XML docs for public API
/// <summary>
/// Retrieves a user by their unique identifier.
/// </summary>
/// <param name="id">The user's unique ID.</param>
/// <returns>The user, or null if not found.</returns>
/// <exception cref="ArgumentException">Thrown when id is negative.</exception>
public Task<User?> GetUserByIdAsync(int id)
{
// ...
}
// ✓ CORRECT - depend on interfaces
public class UserService
{
private readonly IUserRepository _repository;
public UserService(IUserRepository repository)
{
_repository = repository;
}
}
| Mistake | Correct Approach |
|---|---|
Blocking on async (.Result, .Wait()) | Use async/await all the way |
| Missing XML docs on public API | Document with /// XML comments |
public fields | Use properties with get/set |
| Ignoring nullability | Enable <Nullable>enable</Nullable> |
| Imperative loops for collections | Use LINQ |
| Magic strings | Use nameof() or constants |
Catching Exception broadly | Catch specific exception types |
.editorconfig rulesnpx skills add testdino-hq/google-styleguides-skills/csharp
See csharp.md for complete details, examples, and edge cases.