我的问题很简单:我想知道我正在使用哪个版本的C#.如果我将使用python,我会做一些像python -V命令行或类型
import sys
print sys.version
Run Code Online (Sandbox Code Playgroud)
在PHP中我会做这样的事情:phpinfo();在java中:java -version
但我无法在C#中找到如何实现这一目标.
我对C#完全不熟悉,所以请不要太难打败我.令我感到惊讶的是,我无法在SO上找到这个答案,因此我认为我在找东西时遗漏了一些东西或者很糟糕.顺便说一句,这个问题没有回答,虽然名字暗示它应该.
谢谢你的回答.现在我知道它取决于.NET框架,但有没有一种编程方式来确定我的框架?(无需转到目录并检查我的.NET文件夹的名称)
如何从命令提示符窗口编译和执行.cs文件?
问题是我需要知道它是否是版本3.5 SP 1. Environment.Version()只返回2.0.50727.3053.
我找到了这个解决方案,但我认为这需要花费更多的时间而不是它的价值,所以我正在寻找一个更简单的解决方案.可能吗?
C#6为内插字符串文字带来了编译器支持,语法如下:
var person = new { Name = "Bob" };
string s = $"Hello, {person.Name}.";
Run Code Online (Sandbox Code Playgroud)
这对于短字符串很有用,但是如果要生成更长的字符串,必须在一行中指定它吗?
使用其他类型的字符串,您可以:
var multi1 = string.Format(@"Height: {0}
Width: {1}
Background: {2}",
height,
width,
background);
Run Code Online (Sandbox Code Playgroud)
要么:
var multi2 = string.Format(
"Height: {1}{0}" +
"Width: {2}{0}" +
"Background: {3}",
Environment.NewLine,
height,
width,
background);
Run Code Online (Sandbox Code Playgroud)
我无法找到一种方法来实现这一点,使用字符串插值,而不是只有一行:
var multi3 = $"Height: {height}{Environment.NewLine}Width: {width}{Environment.NewLine}Background: {background}";
Run Code Online (Sandbox Code Playgroud)
我意识到在这种情况下你可以用来\r\n代替Environment.NewLine(不太便携),或者把它拉到本地,但是有些情况下你不能将它减少到一行以下而不会失去语义强度.
是不是字符串插值不应该用于长字符串?
我们应该使用StringBuilder更长的字符串吗?
var multi4 = new StringBuilder()
.AppendFormat("Width: {0}", width).AppendLine()
.AppendFormat("Height: {0}", height).AppendLine()
.AppendFormat("Background: {0}", background).AppendLine()
.ToString();
Run Code Online (Sandbox Code Playgroud)
还是有更优雅的东西?
有很多理由想要"转换" .bat到.exe- 隐藏/混淆实现,密码,资源路径,从批处理文件创建服务......主要是为了让你的工作看起来比实际更复杂和重要是.
不想使用第三方工具的原因也很多.
那么如果你想在.exe不使用外部软件的情况下"转换"批处理文件呢?(转换是引号,因为我认为没有真正的方法将批处理文件编译成可执行文件.有太多滥用的错误技术和广泛使用的错误,我知道的所有工具实际上创建了一个临时.bat文件,然后调用它)
在DOS批处理文件中,实现某些事情的方法有些混淆.幸运的是,有一个很棒的批处理脚本参考站点:Simon Sheppard的SS64.(同一网站也有大量关于Bash的信息.)
一个难点是根据目录是否为空来分支执行.显而易见的if exist "%dir%\*.*"是行不通的.但是可以使用这个条件执行技巧来完成:
( dir /b /a "%dir%" | findstr . ) > nul && (
echo %dir% non-empty
) || (
echo %dir% empty
)
Run Code Online (Sandbox Code Playgroud)
另一个尴尬的问题是根据文件内容进行分支.再次,可以这样做:
( fc /B "%file1%" "%file2%" | find "FC: no differences encountered" ) > nul && (
echo "%file1%" and "%file2%" are the same
) || (
echo "%file1%" and "%file2%" are different
)
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:
有没有办法根据文件的时间戳做分支?
这是我想要的东西:
REM *** pseudo-code!
if "%file1%" is_newer_than "%file2%" (
echo …Run Code Online (Sandbox Code Playgroud) 安装VS 2015后,从命令行运行csc.exe会导致此消息显示到控制台:
此编译器作为Microsoft(R).NET Framework的一部分提供,但仅支持C#5以外的语言版本,而C#5不再是最新版本.对于支持较新版本的C#编程语言的编译器,请参阅 http://go.microsoft.com/fwlink/?LinkID=533240
该链接重定向到GitHub上的Roslyn存储库.
那么,是从命令行运行"支持更新版本的编译器"(Roslyn)的方法吗?
我是C#的新手,我正在尝试使用cmd来编译一个名为的基本hello world文件test.cs.它包含以下内容:
// Similar to #include<foo.h> in C++, includes system namespaces in a program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// A name space declaration, a class is a group of namespaces
namespace Program1
{
class Hello // my class here, classes can contain multiple functions called methods which define it's behavior
{
static void Main(string[] args) // main method, just like in C/C++ it's the starting point for execution cycle
{
Console.WriteLine("Hello World"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译某人在使用C#6.0功能时创建的C#项目.
在以前的.NET版本中,当前的C#编译器已自动安装并准备与.NET Framework一起运行.显然,情况已不再如此.我目前在我的机器上安装了.NET 4.6.1,但调用csc告诉我:
Microsoft (R) Visual C# Compiler version 4.6.1055.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only
supports language versions up to C# 5, which is no longer the latest version. Fo
r compilers that support newer versions of the C# programming language, see http
://go.microsoft.com/fwlink/?LinkID=533240
Run Code Online (Sandbox Code Playgroud)
该链接将我转发给Github上的Roslyn项目.它似乎没有提供任何二进制版本.
奇怪的是,谷歌搜索C# 6.0 compiler提出了几个关于如何向Visual Studio …
c# ×7
.net ×4
batch-file ×2
cmd ×2
.net-4.6 ×1
c#-6.0 ×1
command-line ×1
compilation ×1
csc ×1
filesystems ×1
iexpress ×1
installation ×1
multiline ×1
path ×1
roslyn ×1
string ×1
version ×1