Why is list when passed without ref to a function acting like passed with ref?

If I did not get this terribly wrong, this behaviour is strange for me. Rather than explaining, I'll post a sample code below and please tell me why does I get output x and not y. private void button1_Click(object sender, EventArgs e) { List<int> l = new List<int>() { 1, 2, 3 }; Fuss(l); MessageBox.Show(l.Count.ToString()); } private void

为什么列表在没有引用的情况下传递给像ref一样传递的函数?

如果我没有得到这个可怕的错误,这种行为对我来说很奇怪。 而不是解释,我会在下面发布一个示例代码,请告诉我为什么我会得到输出x而不是y。 private void button1_Click(object sender, EventArgs e) { List<int> l = new List<int>() { 1, 2, 3 }; Fuss(l); MessageBox.Show(l.Count.ToString()); } private void Fuss(List<int> l) { l.Add(4);

Differentiating between uninstalling/installing and upgrading an application

So, I have this application for which we are producing further development versions. If the application gets uninstalled by the user (from Add/Remove Programs let's say), then I want the application to delete a certain folder in the file system which contains app-related information. However, if the application is upgraded (by downloading a newer installer for this app and installing it),

区分卸载/安装和升级应用程序

所以,我有这个应用程序,我们正在制作更多的开发版本。 如果应用程序被用户(从添加/删除程序)卸载,那么我希望应用程序删除文件系统中包含与应用程序相关的信息的某个文件夹。 但是,如果应用程序升级(通过下载此应用程序的较新安装程序并安装它),那么我希望它保留该文件夹。 我(目前)的印象是,无法区分卸载/安装和只是将应用程序从一个版本更新到另一个版本,因为.NET部署项目将升级视为另一个卸载/安装过程,但

Oracle Stored Procedure and custom data type

I have an Oracle stored procedure which takes two parameters: a custom data type and a string. Calling the stored procedure in Oracle, I would do the following: EXECUTE MY_STORED_PROCEDURE(MYTYPE_T(99, 231), 'mystring') How can I execute this using C#? I understand that I need to setup the command to be a stored procedure, but how do I specify the first parameter as custom data type? Updat

Oracle存储过程和自定义数据类型

我有一个Oracle存储过程,它有两个参数:一个自定义数据类型和一个字符串。 在Oracle中调用存储过程时,我会执行以下操作: EXECUTE MY_STORED_PROCEDURE(MYTYPE_T(99, 231), 'mystring') 我如何使用C#执行此操作? 我知道我需要将命令设置为存储过程,但是如何将第一个参数指定为自定义数据类型? 更新: MYTYPE_T是通过创建的TABLE OF NUMBER CREATE OR REPLACE TYPE mytype_t AS TABLE OF NUMBER ; 您不能使用已

How to Use Model Validation Rules in WPF ViewModel

I'm using WPF with the MVVM pattern and just starting a very large project. To keep concerns separated, I want to put all my validation rules into my data models. But when I review how to do WPF validation, all the examples that I can find show how to do it with the ViewModel holding the validation rules. Some of these examples show some real deep understanding of WPF and are very cool.

如何在WPF ViewModel中使用模型验证规则

我正在使用WPF和MVVM模式,并开始一个非常大的项目。 为了保持关注点分开,我想将所有验证规则放入我的数据模型中。 但是当我回顾如何进行WPF验证时,我可以找到的所有示例都显示了如何使用包含验证规则的ViewModel进行验证。 其中的一些例子显示了对WPF的深刻理解,并且非常酷。 在这个特定的应用程序中,我在编辑和模型的ViewModels之间建立了1:1映射,所以我可以将它放在ViewModels中。 但它感觉不对。 使用IDataE

How do I add comments to Json.NET output?

Is there a way I can automatically add comments to the serialised output from JSON.Net? Ideally I'd imagine it's something similar to the following: public class MyClass { [JsonComment("My documentation string")] public string MyString { get; set; } } or (even better if annotations can be avoided): public class MyClass { /// <summary> /// My documentation stri

如何添加评论到Json.NET输出?

有没有一种方法可以自动将注释添加到JSON.Net的序列化输出中? 理想情况下,我会想象它是类似于以下内容: public class MyClass { [JsonComment("My documentation string")] public string MyString { get; set; } } 或者(如果可以避免注释,则更好): public class MyClass { /// <summary> /// My documentation string /// </summary> public string MyString { get; set; } }

Deleting element of JArray in for

This question already has an answer here: How do I remove a particular element from an array in JavaScript? 62 answers You can do this manually in a better way; when you find a "faulty" element you want to remove, you just shift all other elements to the left thus overriding the one you don't want. But I think there's no need for you to do that. (if you're adamant in

在for中删除JArray的元素

这个问题在这里已经有了答案: 如何从JavaScript中的数组中删除特定的元素? 62个答案 您可以以更好的方式手动执行此操作; 当你发现一个你想删除的“错误”元素时,你只需将所有其他元素移到左边,从而覆盖你不想要的元素。 但我认为你没有必要这样做。 (如果你坚持这个请求,评论,我会为你提供这样做的代码)。 Remove()方法为你做。 大多数插入元素或从集合中移除的方法都是这样工作的:它们在所需的位置插入/删除

How Do I Delete a DNS Domain Programmatically?

I am building a C# web app to manage our DNS servers and am using the WMI Namespace for everything. The only thing I am having trouble with is deleting DNS Domains. Here is my code: internal static bool DeleteDomainFromDns(string DnsServerName, string ContainerName, string Name) { try { string Query = "SELECT * FROM MicrosoftDNS_Domain WHERE DnsServerName = '" +

如何以编程方式删除DNS域?

我正在构建一个C#web应用程序来管理我们的DNS服务器,并且使用WMI命名空间来处理所有事情。 我唯一遇到的问题是删除DNS域名。 这是我的代码: internal static bool DeleteDomainFromDns(string DnsServerName, string ContainerName, string Name) { try { string Query = "SELECT * FROM MicrosoftDNS_Domain WHERE DnsServerName = '" + DnsServerName + "' AND ContainerName = '" + Con

Make WCF DateTime Compatible for Java client

I'am designing a WCF Service wich will be consumed by Java client by returning an array of object . I design a small Java application to display the output object collection fields. all fine except the DateTime wich is displayed as follow : java.util.GregorianCalendar[time=1370969700000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+01:0

使WCF DateTime兼容Java客户端

我正在设计一个WCF服务,这个服务将被Java客户端通过返回一个对象数组来使用。 我设计了一个小型的Java应用程序来显示输出对象集合字段。 除了日期时间外,所有的细节都显示如下: java.util.GregorianCalendar中[时间= 1370969700000,areFieldsSet =真,areAllFieldsSet =真,宽大=真,区= sun.util.calendar.ZoneInfo [ID = “GMT + 01:00”,偏移量= 360万,dstSavings = 0, useDaylight =假,过渡= 0,lastRule =空]

Format A TimeSpan With Years

I have a class with 2 date properties: FirstDay and LastDay . LastDay is nullable. I would like to generate a string in the format of "x year(s) y day(s)" . If the total years are less than 1, I would like to omit the year section. If the total days are less than 1, I would like to omit the day section. If either years or days are 0, they should say "day/year", rather tha

使用年份格式化TimeSpan

我有一个有两个日期属性的类: FirstDay和LastDay 。 LastDay为空。 我想生成一个字符串,格式为"x year(s) y day(s)" 。 如果总年数小于1,我想省略年份部分。 如果总天数小于1,我想省略天数部分。 如果几年或几天都是0,他们应该说“日/年”,而不是“日/年”。 例子: 2.2年:“2年73天” 1.002738年:“1年1天” 0.2年:“73天” 2年:“2年” 我有作品,但它很长: private const decimal DaysInAYear = 36

How do I generate a random int number in C#?

如何在C#中生成一个随机整数? The Random class is used to create random numbers. (Pseudo-random that is of course.). Example: Random rnd = new Random(); int month = rnd.Next(1, 13); // creates a number between 1 and 12 int dice = rnd.Next(1, 7); // creates a number between 1 and 6 int card = rnd.Next(52); // creates a number between 0 and 51 If you are going to create more than one ran

如何在C#中生成一个随机int数?

如何在C#中生成一个随机整数? Random类用于创建随机数。 (当然是伪随机)。 例: Random rnd = new Random(); int month = rnd.Next(1, 13); // creates a number between 1 and 12 int dice = rnd.Next(1, 7); // creates a number between 1 and 6 int card = rnd.Next(52); // creates a number between 0 and 51 如果你要创建多个随机数,你应该保留Random实例并重用它。 如果你创建新实例的时间太近,它们将