在Visual Studio中测试简单的C#代码表达式 - c#

我想知道如何测试简单的C#表达式

1)在Visual Studio中
2)不在调试中,在设计模式下

说,我想验证什么将返回此代码

?DateTime.ParseExact("2016", "yyyy")

要么

int i;
int.TryParse("x55", out i);
?i

我在即时窗口中获得了以下消息:

?DateTime.ParseExact("2016", "yyyy") 
The expression cannot be evaluated while in design mode.

参考方案

Interactive Window(不要与立即窗口混淆)将实现您想要的。

它可以由View > Other Windows > C# Interactive访问,本质上是一个交互式编译器会话,其运行与项目是否正在执行无关,从而使您可以随意执行代码,而不必构建和运行项目。

这是此窗口中可以执行的操作的示例

> Random gen = new Random();
> DateTime RandomDay()
. {
.     int monthsBack = 1;
.     int monthsForward = 3;
.     DateTime startDate = DateTime.Now.AddMonths(-monthsBack);
.     DateTime endDate = DateTime.Now.AddMonths(monthsForward);    
.     int range = (endDate - startDate).Days;
.     return startDate.AddDays(gen.Next(range));
. }
> RandomDay()
[28/01/2020 15:11:51]

并使用外部dll

> Newtonsoft.Json.Linq.JObject.Parse("{'myArticle': { 'myDate': '2020-03-24T00:00:00'}  }")
(1,1): error CS0103: The name 'Newtonsoft' does not exist in the current context

> #r "C:\Users\MyUser\.nuget\packages\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll"

> Newtonsoft.Json.Linq.JObject.Parse("{'myArticle': { 'myDate': '2020-03-24T00:00:00'}  }")
JObject(1) { JProperty(1) { JObject(3) { JProperty(1) { [24/03/2020 00:00:00] } } } }

在Visual Studio 2017上安装Monogame - c#

我正在尝试在VS 2017上安装Monogame,但是即使我已安装VS 2017,VS 2017安装程序上的选项也会显示为灰色。我也有VS 2015和VS 2010,但是我不确定是否是引起问题的。 MonoGame的版本为3.6.0.1625,我当前具有以下目录:C:\ Users \ MY NAME \ Documents \ Visual Studio …

在Visual Studio Proff中调试本机代码 - c#

我们在这里使用的解决方案包括C#中的一个项目和C中的另一个项目。是否可以在Visual Studio中调试c代码? c#参考方案 当然,如果您有源代码,请从中创建一个项目,作为调试进行编译(添加断点,监视...)并进行调试。

Visual Studio 2012不会让我调试接口的实现 - c#

我正在LINQ中进行一些查询,想了解它的实现,所以我想到了调试的方法,但是当我尝试这样做时,Visual Studio没有进入接口的实现,不知道为什么会这样。我正在使用Visual Studio Community2015。这是我的代码class Client { static void Main(string[] args) { string[] word…

Visual Studio Cant查找文件-调试 - c#

在Visual Studio 2015中进行调试期间,无法找到文件:xxxx.cs not found You need to find xxx.cs to view the source for the current call stack frame Try one of the following options: - Browse and find …

在Visual Studio for 5节点群集中调试Azure Service Fabric应用程序 - c#

我有一个非常简单的用例,需要在Azure Service Fabric中设置5节点群集环境,然后调试代码。我面临的问题是,当我在本地为5节点群集部署应用程序时,由于只有一个节点可以使用计算机上的端口,因此我的应用程序仅在1个节点群集上运行,而部署在其他4个节点上失败因为该端口不可用。我正在寻找在本地环境中部署和测试多节点群集的步骤。我们将不胜感激,并且可以在…