I want to add a comma in the thousands place for a number. String.Format() ? String.Format("{0:n}", 1234); //Output: 1,234.00 string.Format("{0:n0}", 9876); // no digits after the decimal point. Output: 9,876 我发现这是最简单的方法: myInteger.ToString("N0") int number = 1000000000; string whatYouWant = number.ToString("#,##0"); //You get: 1,000,000,000
我想为数字在千位上添加一个逗号。 String.Format() ? String.Format("{0:n}", 1234); //Output: 1,234.00 string.Format("{0:n0}", 9876); // no digits after the decimal point. Output: 9,876 我发现这是最简单的方法: myInteger.ToString("N0") int number = 1000000000; string whatYouWant = number.ToString("#,##0"); //You get: 1,000,000,000
How can brackets be escaped in using string.Format . For example: String val = "1,2,3" String.Format(" foo {{0}}", val); This example doesn't throw an exception, but outputs the string foo {0} Is there a way to escape the brackets? For you to output foo {1, 2, 3} you have to do something like: string t = "1, 2, 3"; string v = String.Format(" foo {{{0}}}", t); To output a { you use {
如何使用string.Format方括号被转义。 例如: String val = "1,2,3" String.Format(" foo {{0}}", val); 此示例不会引发异常,但会输出字符串foo {0} 有没有办法摆脱括号? 为了输出foo {1, 2, 3}你必须做如下的事情: string t = "1, 2, 3"; string v = String.Format(" foo {{{0}}}", t); 要输出一个{你使用{{并输出}你使用}} 。 是的输出{在string.Format你必须像这样转义它{{ 所以这 String val = "1,2,3"; St
Instead of relying on my host to send email, I was thinking of sending the email messages using my Gmail account. The emails are personalized emails to the bands I play on my show. Is it possible to do? Be sure to use System.Net.Mail , not the deprecated System.Web.Mail . Doing SSL with System.Web.Mail is a gross mess of hacky extensions. using System.Net; using System.Net.Mail; var fromAd
我想用我的Gmail帐户发送电子邮件,而不是依靠主人发送电子邮件。 这些电子邮件是我在我的节目中播放的乐队的个性化电子邮件。 有可能吗? 一定要使用System.Net.Mail ,而不是弃用的System.Web.Mail 。 使用System.Web.Mail SSL是一件非常糟糕的事情。 using System.Net; using System.Net.Mail; var fromAddress = new MailAddress("from@gmail.com", "From Name"); var toAddress = new MailAddress("to@example.com",
I'm looking for basically fastest way to display non-editable FlowDocument with continuous, variously decorated text. I know RichTextBox and usually use FlowDowcumentScrollViewer that can display FlowDocument content. I know TextBlock can (kind of) be fed Inlines in code, but doens't support Paragraphs etc. But did anybody measure which of the former two are faster with different occa
我正在寻找基本上最快的方式来显示不可编辑的FlowDocument,并使用连续的,各种装饰的文本。 我知道RichTextBox,并且通常使用FlowDowcumentScrollViewer来显示FlowDocument内容。 我知道TextBlock可以(某种)在代码中被内联,但不支持段落等。 但是有没有人测量过前两种在不同场合(滚动/非滚动,长/短文档等)更快? 还是有其他更有效的解决方案? 有些人声称FlowDowcumentScrollViewer实际上比较慢,因为它支持更多
In the few years I've been using C# (WinForms), I've never used WPF. But, now I love WPF, but I don't know how I am supposed to exit my application when the user clicks on the Exit menu item from the File menu. I have tried: this.Dispose(); this.Exit(); Application.ShutDown(); Application.Exit(); Application.Dispose(); Among many others. Nothing works. To exit your application
在我使用C#(WinForms)的几年中,我从未使用过WPF。 但是,现在我喜欢WPF,但是我不知道当用户从File菜单中单击Exit菜单项时我该如何退出我的应用程序。 我努力了: this.Dispose(); this.Exit(); Application.ShutDown(); Application.Exit(); Application.Dispose(); 等等。 什么都没有 要退出您的应用程序,您可以致电 System.Windows.Application.Current.Shutdown(); 如Application.Shutdown方法的文档中所述,
I come from a mostly web and a little bit Windows Forms background. For a new project, we will be using WPF. The WPF application will need 10 - 20 small icons and images for illustrative purposes. I am thinking about storing these in the assembly as embedded resources. Is that the right way to go ? How do I specify in XAML that an Image control should load the image from an embedded resourc
我主要来自网页和一些Windows窗体背景。 对于一个新项目,我们将使用WPF。 出于说明目的,WPF应用程序需要10-20个小图标和图像。 我正在考虑将这些作为嵌入式资源存储在程序集中。 这是正确的路吗? 如何在XAML中指定Image控件应该从嵌入资源加载图像? 如果您将在多个地方使用图像,那么将图像数据只加载到内存中并在所有Image元素之间共享图像数据是值得的。 为此,请创建一个BitmapSource作为某处的资源: <Bitm
What are the differences in implementing interfaces implicitly and explicitly in C#? When should you use implicit and when should you use explicit? Are there any pros and/or cons to one or the other? Microsoft's official guidelines (from first edition Framework Design Guidelines) states that using explicit implementations are not recommended , since it gives the code unexpected behaviou
在C#中隐式和显式实现接口有什么区别? 什么时候应该使用隐式,何时应该使用显式? 这两种方法有没有优点和/或缺点? 微软官方指导(从第一版框架设计指南)指出, 不建议使用显式实现 ,因为它给代码带来了意想不到的行为。 我认为这个指导方针在IoC时代之前是非常有效的 ,当你不把它作为接口传递时。 任何人都可以涉及这方面? 隐含的是当你通过你的类中的成员定义你的接口。 显式是在接口上的类中定义方法的时
It is May 2017. My boss has asked me to produce some code to make some custom web images on our website based on text that the user enters into their browser. The Server environment is Windows 2012 running IIS, and I am familiar with C#. From what I read I should be able to use GDI+ to create images, draw smooth text into them etc. However, one of my colleagues suggested GDI+ may not work on
这是2017年5月。我的老板要求我产生一些代码,以便根据用户输入到浏览器中的文本在我们的网站上制作一些自定义网页图像。 服务器环境是运行IIS的Windows 2012,并且我熟悉C#。 从我阅读的内容中我应该可以使用GDI +创建图像,在它们中绘制流畅的文本等。 然而,我的一位同事建议GDI +可能无法在Windows Server上工作,而且GDI +是基于32位的旧GDI,因此将在不久的一天内被废弃,并且我应该使用DirectX。 我觉得引入另一层
i am working on a game, but currently I am running benchmarks. If anyone can help me on this matter, I would greatly appreciate it. What I am doing, is I fire the paint event on a panel when I click the start button, with this code: private void startToolStripMenuItem_Click(object sender, EventArgs e) { try { pnlArea.Invalidate(); } catch
我正在制作一款游戏,但目前我正在运行基准测试。 如果有人能够帮助我解决这个问题,我将不胜感激。 我正在做的是,当我点击开始按钮时,使用以下代码触发面板上的绘画事件: private void startToolStripMenuItem_Click(object sender, EventArgs e) { try { pnlArea.Invalidate(); } catch (Exception) { throw; } } 然后我在绘
Problem: I found this function here a few days ago but I couldn't find it again. It resizes images but the output quality is not good. It looks like the color depth is 8 bit. First photo is the original, 2nd is Photoshopped and the last one is resized by the code: Samples: Function: Image ResizeImage(Image original, int targetWidth) { double percent = (double)original.Width / t
问题: 我几天前在这里找到了这个功能,但是我再也找不到它了。 它调整图像大小,但输出质量不好。 它看起来像颜色深度是8位。 第一张照片是原件,第二张是Photoshopped,最后一张是由代码调整大小: 样品: 功能: Image ResizeImage(Image original, int targetWidth) { double percent = (double)original.Width / targetWidth; int destWidth = (int)(original.Width / percent); int destHeight = (i