简体   繁体   English

如何将 VisualStudio 中的 C# 项目保存到单个.cs 文件而不是整个项目文件夹中?

[英]How can I save a C# project in VisualStudio into a single .cs file instead of a whole project folder?

I have been practicing programming this way, but for my exam I will need to hand in a single script file, and I don't know how to do that.我一直在用这种方式练习编程,但为了考试,我需要提交一个脚本文件,我不知道该怎么做。 When I try to create a single file it's totally empty, is there a way of having all that starting structure but still saving only into a single.cs script?当我尝试创建一个文件时它完全是空的,有没有办法拥有所有的起始结构但仍然只保存到一个 single.cs 脚本中?

A "project" ( .csproj file plus one or more .cs files): no.一个“项目”( .csproj文件加上一个或多个.cs文件):没有。 (Unless you mean some archive format like Zip.) (除非您指的是 Zip 之类的存档格式。)

But there is no limit on how many namespaces, classes, etc. can be in one source file.但是一个源文件中可以有多少个命名空间、类等是没有限制的。 While good practice is to put one top level type in one file (member types and partial classes can modify this) this is not required by the compiler.虽然好的做法是将一种顶级类型放在一个文件中(成员类型和部分类可以修改它),但编译器并不要求这样做。

NB.注意。 the use of the term "script" in your question needs better definition here.在您的问题中使用术语“脚本”需要更好的定义。 Typically one refers to "source" files.通常一个是指“源”文件。 Maybe your instructor means "project write up" as a single document, with the expectation you'll include the source in it?也许您的讲师将“项目编写”作为单个文档表示,并期望您将源包含在其中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM