新C#用户 - 引用系统命名空间的问题 [英] New C# User - Problems referencing System namespace

查看:56
本文介绍了新C#用户 - 引用系统命名空间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是最简单的问题吗?我会从一个完整的新手那里得到一整天。

我昨晚在我的笔记本电脑上安装了Visual Studio并且一直在试用/>
今天早上写我的第一个C#程序。我遇到了几个问题,我确定这个论坛上的某个人能够帮助你快速了解这个问题。


我从一个传统的Hello World开始?程序,再次,我的冷杉

C#程序。我很惊讶地发现在IDE生成的代码中引用了System命名空间如何
。另外,我看起来好像IDE生成的代码明确地引用了一些系统名称空间使用符号看起来像是
的系统命名空间。系统::项目?我没有在任何一本C#书中看到这个,我引用了b $ b。这些书中的每一本都暗示你只需要使用系统发布一个?b $ b?我应该能够引用来自
系统名称空间的任何项目。


然后我尝试创建一个值类型的变量?decimal?。看起来好像我喜欢?b $ b?十进制?应该在System命名空间中定义。我注意到的第一个

的事情是IDE没有为关键字着色?decimal?对于我使用过的其他值类型(例如int,string

等),它就像它的b $ b蓝色一样。果然,当我尝试编译程序时,complie

没有识别出关键字?decimal ?.


我确定这些问题都是以某种方式相关的。有人可以直接告诉我一些额外的信息,这些信息有助于弄清楚我在这里做错了什么吗?

在这里做错了所以我可以完成我的前几个C#程序


-

MDoylePosted来自 http ://www.pcreview.co.uk/ 新闻组访问


Here is the easiest question you?ll get all day from a complete newbie.
I installed Visual Studio on my laptop last night and have been tryin
to write my very first C# programs this morning. I?m running into
few issues that I?m sure someone on this forum will be able to help m
understand quickly.

I started out with a traditional ?Hello World? program, again, my firs
C# programs. I was surprised to see how the System namespace wa
referenced in the code that was generated by the IDE. In addition, i
looks like the IDE generates code that explicitly referenced items fro
the System namespace using a notation that looks something lik
?System::item?. I haven?t seen this in any of the C# books that I?v
referenced. Each of these books suggests that you simply need to issu
a ?using System;? and I should be able to reference any item from th
System namespace.

I then tried to create a variable of value type ?decimal?. It looks t
me like ?decimal? should be defined in the System namespace. The firs
thing I noticed was that the IDE did not color the keyword ?decimal? i
blue like it did for the other value types I had used (i.e. int, string
etc.). Sure enough, when I tried to compile the program, the complie
didn?t recognize the keyword ?decimal?.

I?m sure that these issues are all related somehow. Can someone direc
me to some additional information that would help be figure out what I?
doing wrong here so I can get through my first few C# programs

--
MDoylePosted from http://www.pcreview.co.uk/ newsgroup acces

推荐答案

所有.Net语言都使用Common语言运行时(CLR)。 C#将以与其他.Net语言不同的方式向您公开CLR给您。当你提到
时,字符串[string]以蓝色显示,是c#中的关键字。它

等于[System.String]类型。 C#中没有关键字十进制。

System命名空间中有[System.Decimal]结构。它将十进制值类型定义为




~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~

十进制值类型表示正数的十进制数

79,228,162,514,264,337,593,543,950,335为负数

79,228,162,514,264,337,593,543,950,335。十进制值类型是

适用于需要大量

重要积分和小数位且没有舍入错误的财务计算。


十进制数是一个带符号的定点值,由一个完整的

部分和一个可选的小数部分组成。积分和小数部分

由一系列数字组成,范围从0到9(0到9),

用小数点符号分隔。


Decimal实例的二进制表示由1位

96位整数,并指定它的小数部分。

比例系数隐式为数字10,从0到28提升到指数范围




~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >
我的猜测是你可能想要使用关键字[single]或

[double]代表单精度或双精度浮点数。

它们分别等同于System.Single和System.Double。

MDoyle < MDoyle.1qkhla@>在消息中写道

新闻:sI ******************** @ giganews.com ...
All the .Net languages use the Common Language Runtime (CLR). C# will expose
the CLR to you in ways that is different from other .Net languages. As you
mentioned the word [string] is presented in blue and is a keyword in c#. It
equates to the [System.String] type. There is no keyword decimal in C#.
There is the [System.Decimal] structure in the System namespace. It defines
the Decimal Value Type as:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Decimal value type represents decimal numbers ranging from positive
79,228,162,514,264,337,593,543,950,335 to negative
79,228,162,514,264,337,593,543,950,335. The Decimal value type is
appropriate for financial calculations requiring large numbers of
significant integral and fractional digits and no round-off errors.

A decimal number is a signed, fixed-point value consisting of an integral
part and an optional fractional part. The integral and fractional parts
consist of a series of digits that range from zero to nine (0 to 9),
separated by a decimal point symbol.

The binary representation of an instance of Decimal consists of a 1-bit
sign, a 96-bit integer number, and a scaling factor used to divide the
96-bit integer and specify what portion of it is a decimal fraction. The
scaling factor is implicitly the number 10, raised to an exponent ranging
from 0 to 28.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My guess is that you are probably wanting to use the keyword [single] or
[double] which represent single or double precision floating point numbers.
These equate to System.Single and System.Double respectively.
"MDoyle" <MDoyle.1qkhla@> wrote in message
news:sI********************@giganews.com...
<这是你从一个完整的新手那里得到的最简单的问题。
我昨晚在我的笔记本电脑上安装了Visual Studio,并且今天早上一直在努力编写我的第一个C#程序。我正在遇到几个问题,我相信这个论坛上的某个人能够帮助我快速理解。

我从传统开始Hello World程序,再次,我的第一个C#程序。我很惊讶地看到如何在IDE生成的代码中引用System命名空间。此外,它看起来像IDE生成的代码使用类似于
System :: item的符号显式引用了System命名空间中的项目。我没有在我引用的任何C#书中看到过这个。这些书中的每一本都表明你只需要发出一个使用系统;我应该能够引用
System命名空间中的任何项目。

然后我尝试创建一个值类型为decimal的变量。它看起来像是十进制。应该在System命名空间中定义。我注意到的第一件事是IDE没有为关键字十进制着色。
蓝色,就像我用过的其他值类型一样(即int,string,
等)。果然,当我尝试编译程序时,编译器没有识别出关键字十进制。

我确信这些问题都是以某种方式相关的。有人可以直接向我提供一些有助于弄清楚我在这里做错了什么的其他信息,这样我就能完成我的前几个C#程序吗?

- -
MDoylePosted来自 http://www.pcreview.co.uk/新闻组访问



您确定要制作C#程序吗?

看起来,您正在制作C ++程序。

::运算符是C ++的一部分,但不是C#1.0的一部分(但是C#2.0中有一个)

decimal是C#的关键字,但不是C ++。


Christof


" MDoyle" < MDoyle.1qkhla@> schrieb im Newsbeitrag

新闻:sI ******************** @ giganews.com ...
Are you sure your making a C# program?
Looks like, your making a C++ programm instead.
The :: operator is part of C++ but not of C#1.0 (but there is one in C#2.0)
decimal is a keyword of C#, but not of C++.

Christof

"MDoyle" <MDoyle.1qkhla@> schrieb im Newsbeitrag
news:sI********************@giganews.com...
<这是你从一个完整的新手那里得到的最简单的问题。
我昨晚在我的笔记本电脑上安装了Visual Studio,并且今天早上一直在努力编写我的第一个C#程序。我正在遇到几个问题,我相信这个论坛上的某个人能够帮助我快速理解。

我从传统开始Hello World程序,再次,我的第一个C#程序。我很惊讶地看到如何在IDE生成的代码中引用System命名空间。此外,它看起来像IDE生成的代码使用类似于
System :: item的符号显式引用了System命名空间中的项目。我没有在我引用的任何C#书中看到过这个。这些书中的每一本都表明你只需要发出一个使用系统;我应该能够引用
System命名空间中的任何项目。

然后我尝试创建一个值类型为decimal的变量。它看起来像是十进制。应该在System命名空间中定义。我注意到的第一件事是IDE没有为关键字十进制着色。
蓝色,就像我用过的其他值类型一样(即int,string,
等)。果然,当我尝试编译程序时,编译器没有识别出关键字十进制。

我确信这些问题都是以某种方式相关的。有人可以直接向我提供一些有助于弄清楚我在这里做错了什么的其他信息,这样我就能完成我的前几个C#程序吗?

- -
MDoylePosted来自 http://www.pcreview.co.uk/新闻组访问





霍华德,

变量小计如果是值类型十进制。变量是bein

,它们都定义为十进制数,并用

文本框的值进行初始化(在转换方法转换为十进制之后)。


private void btnCalculate_Click(object sender,System.EventArgs e)

{

decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);

十进制discountPercent = 0m;

if(小计> = 500)

discountPercent = .2m;

else if(小计> =&&小计< 500)

discountPercent = .15m;

else if(小计> = 100&&小计< 250)

discountPercent = .1m;

decimal discountAmount = subtotal * discountPercent;

decimal invoiceTotal = subtotal - discountAmount;

lblDiscountPercent.Text = discountPercent.ToString(" p1");

lblDiscountAmount.Text = discountAmount.ToString(" c");

lblTotal .Text = invoiceTotal.ToString(" c" );

txtSubtotal.Focus();

}


我可以从发布商的网站下载示例代码现场。那个
示例代码comples并运行得很好。在使用IDE o

时,示例代码为decimal。是蓝色的,就像其他价值类型一样。

一切都按书的方式工作。


然而,当我试图让IDE生成

程序的基本shell,我尝试创建一个像subtotal这样的变量。从这个例子来看,它看起来并不像IDE或者编译器知道的那样......或者是
" decimal"是。此外,IDE生成的程序已完整o

对系统名称空间的各种显式引用。例如

,而上述示例的声明如下:

private void btnCalculate_Click(object sender,System.EventArgs e)


我怀疑如果我让IDE生成这个代码,它会看起来像是:b $ b像:


private:System :: Void btnCalculate_Click (System :: Object * sender

System :: EventArgs * e)


所有这些System ::是什么?所有关于的前缀。因为IDE生成的代码包含语句usin

命名空间系统,所以我认为是
。我不需要所有这些参考资料t

" System ::"


-

MDoylePosted来自 http://www.pcreview.co.uk/ 新闻组访问


Howard,

Thanks for the quick reply. I''m confused. I''ve paged through three C
book and I do not understand what you are telling me. Below is sampl
code from one of these books Murach''s C#. The way I read this, th
variable "subtotal" if of value type "decimal". The variable is bein
both defined as a decimal number and initialized with the vale of
text box (after being converted to decimal by the convert method).

private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);
decimal discountPercent = 0m;
if (subtotal >= 500)
discountPercent = .2m;
else if (subtotal >= 250 && subtotal < 500)
discountPercent = .15m;
else if (subtotal >= 100 && subtotal < 250)
discountPercent = .1m;
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
lblDiscountPercent.Text = discountPercent.ToString("p1");
lblDiscountAmount.Text = discountAmount.ToString("c");
lblTotal.Text = invoiceTotal.ToString("c");
txtSubtotal.Focus();
}

I can download the sample code from the publisher''s web site. Th
sample code comples and runs just fine. While working with the IDE o
the sample code, "decimal" is in blue just like the other value types.
Everything works just the way the book indicates.

However, when I''ve tried to let the IDE generate the basic shell of
program and I try to create a variable like "subtotal" from thi
example, it does not appear as if the IDE or the compler knows wha
"decimal" is. In addition, the program generated by the IDE is full o
all sorts of explicit references to the system namespace. For example
while the declaration for the above example looks like:

private void btnCalculate_Click(object sender, System.EventArgs e)

I suspect that if I let the IDE generate this code it would look mor
like:

private: System::Void btnCalculate_Click(System::Object * sender
System::EventArgs * e)

What are all of these "System::" prefixes all about. I thought tha
since the code generated by the IDE incuded the statement "usin
namespace System;" that I wouldn''t need all of these references t
"System::"

--
MDoylePosted from http://www.pcreview.co.uk/ newsgroup acces


这篇关于新C#用户 - 引用系统命名空间的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆