【c# – String.Join返回×而不是时间?】教程文章相关的互联网学习教程文章

c# – 如何使用callvirt调用base.ToString()会导致StackOverflow异常?【代码】

IL为调用函数提供了两个语句,即call和callvirt.调用用于调用非虚函数或静态函数或编译器不希望对引用进行空检查的任何函数. callvirt用于调用虚函数,也调用非虚函数,因为编译器在运行时对引用进行空检查. 现在,当通过C#进行CLR时,我发现了以下示例.internal class SomeClass {public override String ToString(){return base.ToString();} }现在ToString()是虚函数,但是编译器为它生成了调用指令.但杰弗里提到为什么没有生成callvi...

c# – 将一个String与一组通配符进行比较的最快方法【代码】

我有一个字典,我的密钥是带有通配符的字符串.我想知道一个字符串是否与dictinary中的任何键匹配. 例:String str = "Really Large String"; Dictionary dic = new Dictionary<String, MyClass>(); dic.Add("First+Match*", new MyClass()); dic.Add("*Large*", new MyClass());编辑:我想做的事情如下:foreach(var s in dic.Keys){if(str.Match(s))//Do Something }解决方法:为什么不,var dic = Dictionary<Regex, MyClass>() dic...

c# – 自定义StringLength验证属性的客户端验证【代码】

我有以下自定义验证属性,它派生自StringLengthAttribute:public class StringLengthLocalizedAttribute : StringLengthAttribute {public StringLengthLocalizedAttribute(int maximumLength) : base(maximumLength){var translator = DependencyResolver.Current.GetService<ITranslator();var translatedValue = translator.Translate("MaxLengthTranslationKey", ErrorMessage);ErrorMessage = translatedValue.Replace("{MaxL...

c# – 为什么Process.Start(string)为WMV文件返回null【代码】

所以我有一个WMV视频文件:var fileName = @"C:\MyFolder\MyVideo.WMV"我正在启动视频并使用代码获取我的Process ID:var process = Process.Start(fileName); if (process != null) {processId = process.Id; }虽然我的视频文件启动,但进程始终为null. 从Process.Start(string) MSDN我可以看到:Return Value Type: System.Diagnostics.Process A new Process that isassociated with the process resource, or null if no proces...

c# – 绑定到Static类属性和StringFormat【代码】

我能够将静态类属性绑定到MenuItem头,但我无法确定如何包含StringFormat,以便除了属性之外我还可以显示硬编码文本. 这可能吗? 目前:(显示“SQLSERVER1”)Header="{x:Static settings:Settings.CurrentServer}"所需:(显示“连接:SQLSERVER1”)Header="{Binding Source={x:Static Settings:Settings.CurrentServer},StringFormat='Connection: {0}'}"当我在XAML中尝试’Desired’行时,完全忽略StringFormat.我究竟做错了什么?解决...

c# – Graphics.DrawString如何在绘制后删除它(undo-redo)?【代码】

有没有办法拉绳然后删除它? 我已经使用以下类来撤消/重做矩形,圆形,直线,箭头类型的形状,但无法想象我如何删除绘制的字符串. https://github.com/Muhammad-Khalifa/Free-Snipping-Tool/blob/master/Free%20Snipping%20Tool/Operations/UndoRedo.cs https://github.com/Muhammad-Khalifa/Free-Snipping-Tool/blob/master/Free%20Snipping%20Tool/Operations/Shape.cs https://github.com/Muhammad-Khalifa/Free-Snipping-Tool/blob...

c# – 如何使用string.Join将Jagged数组与分隔符连接?【代码】

我怎样才能解决下面的字符串连接错误.我将int值转换为字符串值但发生错误….查看Join方法using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data;namespace SortArrayYusuf {class Program{static void Main(string[] args){//int[] array;//using (DataTable table = GetTable())//{// array = (from DataRow row in table.Rows// select// (from...

c# – 为什么在DataSource中返回String.Length而不是实际值【代码】

我有这个代码,它构建了一个IList< string>:IList<string> databases;using (MySqlConnection _conn = Session.Connection) using (MySqlCommand _cmd = _conn.CreateCommand("SHOW databases")) {_cmd.Connection.Open ( );var _dr = _cmd.ExecuteReader();databases = new List<string> ( _dr.SelectFromReader ( reader =>reader[ 0 ] is DBNull ? null : reader[ 0 ].ToString ( ) ) );_cmd.Connection.Close ( ); }dgrid_Main...

c# – IFormatProvider从double到string的科学转换 – 位数【代码】

我有从double到string的转换问题. 我想转换:double value: 0.0772486324655191 string value: 0.0772486324655191如果长度大于小数点后的16位数,我希望它像这样:double value: 0.00063500244832493823 string value: 6.3500244832493823e-004我试图用IFormatProvider模式转换它:0.0000000000000000e000但第一种情况的结果是7.7248632465519100e-002如何获取双向量中的位数?或者更好:我应该如何正确使用格式提供程序?String s...

C#WebClient DownloadString返回乱码【代码】

我试图使用代码查看http://simpledesktops.com/browse/desktops/2012/may/17/where-the-wild-things-are/的来源:String URL = "http://simpledesktops.com/browse/desktops/2012/may/17/where-the-wild-things-are/";WebClient webClient = new WebClient();webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4"); webClient.Encoding = Encoding.GetEncoding...

c# – 处理WPF菜单HeaderStringFormat和Access Keys等【代码】

好的.所以我希望我的应用程序在其主菜单中显示“保存”和“另存为…”项目,就像Visual Studio一样;即“保存{当前文件}”和“保存{当前文件}为…” 我还想拥有普通的访问密钥(分别为“S”和“A”). 我想出了两个解决方案,但两者都不是很理想. >而不是仅仅在xaml中创建主菜单,我可以在MainWindowViewModel中创建所有内容,这样我就可以完全控制生成的MenuItems的内容.但是,我觉得这会违反MVVM(我这次试图非常严格地遵守),因为我必须在...

C#等价于stringByAddingPercentEscapesUsingEncoding?

我正试图找到一种方法来模仿来自iPhone的stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding的行为,使用C#(对于Windows Phone). 我对iPhone编程一无所知,网络搜索似乎没有提供任何文档页面可能解释它实际上做了什么来帮助我弄清楚如何模仿它.我的意思是,我可以看到它使用编码“百分之百逃逸”一个字符串,但我找不到任何示例来确认我将获得的输出是正确的.它只是一个简单的URL编码吗?解决方法:我不确定我是否理解你...

c# – Enum.ToString(),它遵循EnumMemberAnnotation【代码】

我有一个使用EnumMember注释的枚举,以方便JSON.NET序列化,类似于以下内容:[DataContract] [JsonConverter(typeof(StringEnumConverter))] public enum Status {[EnumMember(Value = "NOT_ADMITTED")]NotAdmitted,[EnumMember(Value = "ADMITTED")]Admitted }现在,独立于JSON.NET序列化,我希望将enum的实例转换为字符串,同时遵守数据协定中的EnumMember注释,例如: aStatusInstance.ToString()==“NOT_ADMITTED”. 有什么建议?谢谢...

c# – 在RunTime设置ConnectionString【代码】

我是C#编程的初学者. 我需要编辑/设置/更改我存储在app.config中的连接字符串,我正在使用VS数据库向导来创建查询. 如果你能编写代码那将是非常好的:)解决方法:这样的事情应该让你开始:using System.Configuration;var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var connectionStrings = config.ConnectionStrings; foreach (var connectionString in connectionStrings.ConnectionStrin...

c# – 当Uri TryCreate完美运行时,使用Uri IsWellFormedUriString【代码】

我正在使用代码:Uri.TryCreate(sURL, UriKind.Absolute, out URI)哪个工作正常. 我需要调用Uri.IsWellFormedUriString(sURL,UriKind.Absolute)吗?我的意思是,当Uri.TryCreate完美运行时,我想知道Uri.IsWellFormedUriString的用途是什么?解决方法:Uri.IsWellFormedUriString在内部调用TryCreate以及调用Uri.IsWellFormedOriginalString,因此结果可能与简单地调用TryCreate不同. 来自ILSpypublic static bool IsWellFormedUriStri...