473,416 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

New C# User - Problems referencing System namespace


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
9 2913
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
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

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
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

Richard,

I'm using Visual Studio.NET 2003

Thanks,

Mart

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

Nov 17 '05 #6

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

Thanks

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

Nov 17 '05 #7

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
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
<"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Roberto Modica | last post by:
Hi all, I am trying to create a namespace hierachy but i think i am doing something wrong. I have an DAL vb file with the namespace: CompanyName.newsletter.DAL and i compile that using...
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
1
by: Josh | last post by:
I am trying to move some of my more common controls into user controls. However, I seem to have problems maintaining state of databound controls that are contained within user controls. On...
5
by: Paul Bromley | last post by:
Can someone give me a very simple example on how to do this? As an example I have a commaned button in a user control. Once this user control is placed on a form I want to be able to respond in the...
1
by: Kirk Groome | last post by:
Hi all, I'm working on a web site and I would like to use the VS login controls. The problem I'm having is that when I create a new user all works fine. The user gets added to the database and...
8
by: per9000 | last post by:
Dear readers, I have some problems with strong keys. What I want to do is basically this. A - create an application (f.x. strongHello.dll) with a strong key. B - import the functions of this...
9
by: keith | last post by:
I use this code to load a user control at runtime: Control c = Page.LoadControl(Request.ApplicationPath + "/User_Controls/website_design.ascx"); UserControlPlaceHolder.Controls.Add(c); ...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
2
by: Bronquites | last post by:
Hi! I'm having a problem with a User Control that I want to implement in my project. All the variables and classes are declared as Public. My User Control has a procedure that calls the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.