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.
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.
How to open 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. For a step-by-step walkthrough, see how to open a .cs file.
Windows
- Visual Studio
- VS Code
- any text editor
macOS
- VS Code
- Rider
- any text editor
Linux
- VS Code
- Rider
- any text editor
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.
.cs file signature (magic bytes)
Programs recognise a .cs file by the bytes at the start of the file, not by its name. These are the signatures for C#.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
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: