By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

New C# User - Problems referencing System namespace

P: n/a

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

Nov 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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...

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 trying
to write my very first C# programs this morning. I'm running into a
few issues that I'm sure someone on this forum will be able to help me
understand quickly.

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

I then tried to create a variable of value type "decimal". It looks to
me like "decimal" should be defined in the System namespace. The first
thing I noticed was that the IDE did not color the keyword "decimal" in
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 complier
didn't recognize the keyword "decimal".

I'm sure that these issues are all related somehow. Can someone direct
me to some additional information that would help be figure out what I'm
doing wrong here so I can get through my first few C# programs?
--
MDoylePosted from http://www.pcreview.co.uk/ newsgroup access

Nov 17 '05 #2

P: n/a
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...

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 trying
to write my very first C# programs this morning. I'm running into a
few issues that I'm sure someone on this forum will be able to help me
understand quickly.

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

I then tried to create a variable of value type "decimal". It looks to
me like "decimal" should be defined in the System namespace. The first
thing I noticed was that the IDE did not color the keyword "decimal" in
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 complier
didn't recognize the keyword "decimal".

I'm sure that these issues are all related somehow. Can someone direct
me to some additional information that would help be figure out what I'm
doing wrong here so I can get through my first few C# programs?
--
MDoylePosted from http://www.pcreview.co.uk/ newsgroup access

Nov 17 '05 #3

P: n/a

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

Nov 17 '05 #4

P: n/a
Ummm, C# does have a decimal keyword.

Which version of Visual Studio are we talking about: Visual Studio.NET 2003 - the current live version, or one of the variations of Visual Studio 2005 (Visual C# Express, Visual Studio 2005 Professional/Team System/etc)?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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:

Nov 17 '05 #5

P: n/a

Richard,

I'm using Visual Studio.NET 2003

Thanks,

Mart

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

Nov 17 '05 #6

P: n/a

That's it! I'm such a goof!

Thanks

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

Nov 17 '05 #7

P: n/a

Special thanks to Christof Nordiek. Somehow I got two separate thread
going on this topic and Christof commented:
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 i C#2.0)decimal is a keyword of C#, but not of C++. Christof


I'm such a goof! It looks like I created a C++ project instead of a C
project this morning and have been struggling with trying to get C# cod
to work in a C++ program.

Again, I am such a goof! Thanks for all of your help

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

Nov 17 '05 #8

P: n/a
Whoops, Sorry, Your right. I was unfamiliar with the decimal keyword. My
apologies:
The decimal keyword denotes a 128-bit data type. Compared to floating-point
types, the decimal type has a greater precision and a smaller range, which
makes it suitable for financial and monetary calculations.
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
message news:uY**************@TK2MSFTNGP14.phx.gbl...
Ummm, C# does have a decimal keyword.

Which version of Visual Studio are we talking about: Visual Studio.NET
2003 - the current live version, or one of the variations of Visual Studio
2005 (Visual C# Express, Visual Studio 2005 Professional/Team System/etc)?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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:

Nov 17 '05 #9

P: n/a
<"Howard Swope" <howardsnewsATspitzincDOTcom>> wrote:
Whoops, Sorry, Your right. I was unfamiliar with the decimal keyword. My
apologies:
The decimal keyword denotes a 128-bit data type. Compared to floating-point
types, the decimal type has a greater precision and a smaller range, which
makes it suitable for financial and monetary calculations.


Note that despite the text above, decimal itself is a floating point
type. Fortunately MSDN has been corrected for .NET v2.0 :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.