.cs

What is a .cs file?

C Sharp Source File · Code and data · Microsoft · 2000

A .cs file is C# source code, Microsoft's modern language for the .NET platform. It is used for Windows apps, web backends with ASP.NET, and games built in Unity.

Category
Code and data
MIME type
Type
Plain text
Is a .cs file safe to open? Caution. A .cs file is program source. Building and running it executes its code; review unfamiliar files first.

What is a .cs file used for?

C# is a strongly typed, object-oriented language compiled to run on .NET. Projects are built with the dotnet command or Visual Studio, producing applications that run on Windows, macOS and Linux.

Unity uses C# for game scripting, so many game projects are full of .cs files. The source is plain text and opens in any editor; Visual Studio and VS Code are the usual tools.

What opens a .cs file?

The .cs format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • Visual Studio
  • VS Code
  • any text editor

macOS

  • VS Code
  • Rider
  • any text editor

Linux

  • VS Code
  • Rider
  • any text editor

Open a .cs file step by step

  1. Confirm the file really is a .cs. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with Visual Studio or VS Code.
  3. On Mac, use VS Code or Rider.
  4. On Linux, try VS Code or Rider.
  5. Still stuck? Convert the .cs to dll, which opens more widely.

Why can't I open my .cs file?

Almost always because no installed app understands C#. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .cs at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

How to convert a .cs file

You can convert a .cs file to dll, exe (via dotnet build) using a conversion tool or the export menu of an app that opens it.

C# has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

Frequently asked questions

What is a .cs file?

A .cs file is C# source code, Microsoft's modern language for the .NET platform. It is used for Windows apps, web backends with ASP.NET, and games built in Unity.

How do I run a .cs file?

Inside a .NET project, dotnet run builds and runs it. Visual Studio and VS Code can build and debug C# directly.

Is C# only for Windows?

No longer. Modern .NET runs C# on Windows, macOS and Linux, and Unity uses it for games on many platforms.

How do I open a .cs file?

Any text editor shows the source. Visual Studio or VS Code add highlighting, building and debugging.

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.