How to get the URL of the current page in C#

This question already has an answer here: Get URL of ASP.Net Page in code-behind [duplicate] 10 answers 尝试这个 : string url = HttpContext.Current.Request.Url.AbsoluteUri; // http://localhost:1302/TESTERS/Default6.aspx string path = HttpContext.Current.Request.Url.AbsolutePath; // /TESTERS/Default6.aspx string host = HttpContext.Current.Request.Url.Host; // localhost You may at times need

如何在C#中获取当前页面的URL

这个问题在这里已经有了答案: 在代码隐藏中获取ASP.Net页面的URL 10个答案 尝试这个 : string url = HttpContext.Current.Request.Url.AbsoluteUri; // http://localhost:1302/TESTERS/Default6.aspx string path = HttpContext.Current.Request.Url.AbsolutePath; // /TESTERS/Default6.aspx string host = HttpContext.Current.Request.Url.Host; // localhost 您有时可能需要从URL获取不同的值。 以下示例显示了提

Is a double really unsuitable for money?

I always tell in c# a variable of type double is not suitable for money. All weird things could happen. But I can't seem to create an example to demonstrate some of these issues. Can anyone provide such an example? (edit; this post was originally tagged C#; some replies refer to specific details of decimal , which therefore means System.Decimal ). (edit 2: I was specific asking for som

双倍真的不适合金钱吗?

我总是在c#中告诉一个double类型的变量不适合金钱。 所有奇怪的事情都可能发生。 但我似乎无法创建一个示例来展示其中的一些问题。 任何人都可以提供这样的例子? (编辑;这篇文章最初被标记为C#;一些回复指的是decimal具体细节,因此意味着System.Decimal )。 (编辑2:我具体要求一些C#代码,所以我不认为这只是语言不可知的) 非常非常不合适。 使用小数。 double x = 3.65, y = 0.05, z = 3.7; Console.WriteL

How do I round a decimal value to 2 decimal places (for output on a page)

When displaying the value of a decimal currently with .ToString() , it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places. Do I use a variation of .ToString() for this? decimalVar.ToString ("#.##"); // returns "" when decimalVar == 0 要么decimalVar.ToString ("0.##"); // returns "0" when decimalVar

如何将十进制值舍入为2个小数位(用于页面上的输出)

当用.ToString()显示当前小数的值时,它精确到15位小数,因为我用它来表示美元和美分,所以我只希望输出为2位小数。 我为此使用了.ToString()的变体吗? decimalVar.ToString ("#.##"); // returns "" when decimalVar == 0 要么decimalVar.ToString ("0.##"); // returns "0" when decimalVar == 0 我知道这是一个古老的问题,但我很惊讶地发现没有人似乎发布了答案; 没有使用银行家四舍五入 没有将值保留为小数。

Pass Method as Parameter using C#

I have several methods all with the same signature (parameters and return values) but different names and the internals of the methods are different. I want to pass the name of the method to run to another method that will invoke the passed in method. public int Method1(string) { ... do something return myInt; } public int Method2(string) { ... do something different return myI

使用C#将参数传递为参数

我有几个方法都具有相同的签名(参数和返回值),但名称不同,并且方法的内部是不同的。 我想将方法​​的名称传递给另一个将调用传入方法的方法。 public int Method1(string) { ... do something return myInt; } public int Method2(string) { ... do something different return myInt; } public bool RunTheMethod([Method Name passed in here] myMethodName) { ... do stuff int i = myMethodNa

When to use ref vs out

Someone asked me the other day when they should use the parameter keyword out instead of ref . While I (I think) understand the difference between the ref and out keywords (that has been asked before) and the best explanation seems to be that ref == in and out , what are some (hypothetical or code) examples where I should always use out and not ref . Since ref is more general, why do you ever

何时使用ref vs out

有人问我有一天当他们应该使用参数关键字out ,而不是ref 。 虽然我(我认为)理解ref和out关键字之间的区别(以前已经提到过),并且最好的解释似乎是ref == in和out ,但是我应该始终如此的一些(假设或代码)示例out而不是ref 。 由于ref较为一般,为什么你想用out ? 它只是语法糖吗? 您应该使用out ,除非你需要ref 。 当需要将数据整理到例如另一个过程时,这会产生很大的差异,这可能是昂贵的。 所以当这个方法

typedef struct vs struct definitions

This question already has an answer here: Why should we typedef a struct so often in C? 15 answers The common idiom is using both: typedef struct X { int x; } X; They are different definitions. To make the discussion clearer I will split the sentence: struct S { int x; }; typedef struct S S; In the first line you are defining the identifier S within the struct name space (n

typedef结构与结构定义

这个问题在这里已经有了答案: 为什么我们应该在C中经常输入一个结构体? 15个答案 常见的习惯用法是: typedef struct X { int x; } X; 它们是不同的定义。 为了使讨论更清晰,我将分割这句话: struct S { int x; }; typedef struct S S; 在第一行中,您将在结构体名称空间中定义标识符S (而不是C ++意义上的)。 您可以使用它并通过将参数的类型定义为struct S来定义新定义类型的变量或函数参数: v

When should I use double instead of decimal?

I can name three advantages to using double (or float ) instead of decimal : Uses less memory. Faster because floating point math operations are natively supported by processors. Can represent a larger range of numbers. But these advantages seem to apply only to calculation intensive operations, such as those found in modeling software. Of course, doubles should not be used when precisio

什么时候应该使用double而不是小数?

我可以列举使用double (或float )而不是decimal三个优点: 使用较少的内存。 因为浮点数学运算本来就受到处理器的支持,所以速度更快。 可以代表更大范围的数字。 但是这些优势似乎仅适用于计算密集型操作,如建模软件中的那些。 当然,如果需要精确度,例如财务计算,则不应使用双打。 那么是否有任何实际的理由在“正常”应用程序中选择double (或float )而不是decimal ? 编辑补充:感谢所有的伟大回应,我从他

Why is this output when compare a float and a double

This question already has an answer here: Difference between decimal, float and double in .NET? 17 answers When you do the first assignment, the constant is truncated to fit the float . When you do the second assignment, the float -precision literal 1.1111...11F is converted to double . Since c contains the value of the 1.1111...11F literal, initialization of d is equivalent to double d =

为什么在比较一个浮点数和一个双精度数时输出结果?

这个问题在这里已经有了答案: .NET中decimal,float和double的区别? 17个答案 当你做第一次赋值时,常量被截断以适合float 。 当你做第二次赋值时, float -precision文字1.1111...11F被转换为double 。 由于c包含1.1111...11F文字的值,所以d初始化等同于 double d = ((double)c); 这两个赋值都会改变文字常量的精度,但它们会以不同的方式进行更改。 这就是为什么你在前两个WriteLine看到不同的打印输出。 当你

> Decimal not exactly

Possible Duplicate: What is the difference between Decimal, Float and Double in C#? Help me. I am developing a application in C# . I am trying: DateTime dtm1 = new DateTime(2012, 11, 15, 11, 3, 0); DateTime dtm2 = new DateTime(2012, 11, 15, 11, 3, 20); TimeSpan timespan3 = dtm2 - dtm1; decimal _Hour = Convert.ToDecimal(timespan3.TotalHours); When do such me with output as follows: _Hou

>小数不完全

可能重复: C#中的Decimal,Float和Double有什么区别? 帮我。 我正在用C#开发一个应用程序。 我在尝试: DateTime dtm1 = new DateTime(2012, 11, 15, 11, 3, 0); DateTime dtm2 = new DateTime(2012, 11, 15, 11, 3, 20); TimeSpan timespan3 = dtm2 - dtm1; decimal _Hour = Convert.ToDecimal(timespan3.TotalHours); 当这样做我输出如下: _Hour = 0.00555555555555556M 而且不完全一样,使用时是一种双输出

C# issue with double number

This question already has an answer here: Difference between decimal, float and double in .NET? 17 answers Welcome to floating point precision. Use the decimal type if you want more precision. decimal my_value = 0.49m; If you want to learn more on why this is I recommend you read this article - What Every Computer Scientist Should Know About Floating-Point Arithmetic Use decimal instead

C#问题与双号码

这个问题在这里已经有了答案: .NET中decimal,float和double的区别? 17个答案 欢迎使用浮点精度。 如果您想要更高精度,请使用decimal类型。 decimal my_value = 0.49m; 如果你想了解更多关于这是为什么我建议你阅读这篇文章 - 每个计算机科学家应该知道什么关于浮点运算 使用decimal代替, double是浮点二进制点类型。 decimal my_value = 0.49m; 有用的链接; 浮点表示和精度 每位计算机科学家应该了解的浮点