473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ask a Language Designer: boolean: C# vs. Xml

Why is the default text representation for booleans in C# 'True' and 'False'
whereas in xml it is 'true' and 'false'?

It seems like it would make sense to have them both the same.

Metro T. Sauper, Jr.
President
Sauper Associates, Inc.
Nov 15 '05 #1
8 3241
Metro, I'm not sure what you mean by the default text representation of a
boolean. In C# code booleans appear as true and false. WRT to making them
the same as XML, there is no connection between XML and C# other than C# can
read, write and process XML. One could ask the same thing as to why in
VB.Net they are True and False vs true and false, or C++, or probably many
different languages. I'm curious why you would think that C# syntax or
defaults should be driven by one standard (xml) over any other.

What are you doing that brought this up?

--
Greg Ewing [MVP]
http://www.citidc.com/


"Metro Sauper" <ms*****@sauper.com> wrote in message
news:O2**************@TK2MSFTNGP09.phx.gbl...
Why is the default text representation for booleans in C# 'True' and 'False' whereas in xml it is 'true' and 'false'?

It seems like it would make sense to have them both the same.

Metro T. Sauper, Jr.
President
Sauper Associates, Inc.

Nov 15 '05 #2
Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
Metro, I'm not sure what you mean by the default text representation of a
boolean.


Try this:

using System;

public class Test
{
static void Main()
{
Console.WriteLine (true.ToString());
Console.WriteLine (false.ToString());
}
}

That prints:

True
False

I'm pretty sure that's what the OP was talking about.

It's not C# that does this, of course, but .NET itself.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Ah, I see. Metro, is that what you are talking about?

--
Greg Ewing [MVP]
http://www.citidc.com/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
Metro, I'm not sure what you mean by the default text representation of a boolean.


Try this:

using System;

public class Test
{
static void Main()
{
Console.WriteLine (true.ToString());
Console.WriteLine (false.ToString());
}
}

That prints:

True
False

I'm pretty sure that's what the OP was talking about.

It's not C# that does this, of course, but .NET itself.

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

Nov 15 '05 #4
In .NET, they are (I think) Boolean.True and Boolean.False. In C#, they are
true and false. .NET isn't C#.
Nov 15 '05 #5

Hi,

I think the true, false in C# are the type value of C#, and it is the
mapping of .Net Framework type value. While in .Net, this type value is
True and False.
This is similiar as the int vs Int32, string vs String type mapping
relationship.

Hope this help,

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: Jon Skeet [C# MVP] <sk***@pobox.com>
| Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| Date: Fri, 24 Oct 2003 18:55:27 +0100
| Message-ID: <MP************************@msnews.microsoft.com >
| References: <O2**************@TK2MSFTNGP09.phx.gbl>
<uL**************@TK2MSFTNGP12.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: MicroPlanet Gravity v2.60
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: cpc3-rdng5-6-0-cust143.winn.cable.ntl.com
81.103.154.143
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193868
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
| > Metro, I'm not sure what you mean by the default text representation of
a
| > boolean.
|
| Try this:
|
| using System;
|
| public class Test
| {
| static void Main()
| {
| Console.WriteLine (true.ToString());
| Console.WriteLine (false.ToString());
| }
| }
|
| That prints:
|
| True
| False
|
| I'm pretty sure that's what the OP was talking about.
|
| It's not C# that does this, of course, but .NET itself.
|
| --
| Jon Skeet - <sk***@pobox.com>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
|

Nov 15 '05 #6
The specific issue that brought this to mind is as follows:

We are using xml to store some default configuration for reports. An xml
entry might appear as follows:

<Parameter Name="ShowDetail" Type="System.Boolean" Value="true" />

Now normally with xml, we use "XmlConvert.ToBoolean(string)" to convert
values from xml to the specific datatype, in this case boolean.

However, because the datatype is defined in the entry and not predefined, I
wanted to use the Convert.ChangeType() method to evaluate the entry.
Somthing like:

object parameterValue = Convert.ChanageType(node.Attributes["Value"].Value,
System.GetType(node.Attributes[Type].Value));

However, this did not work because we configured the value as "true" rather
than "True". So now our configuration xml has "true/false" everywhere there
are boolean values EXCEPT for the parameter values where the value is
"True/False" since we use the XmlConvert for all values other than the ones
where we would like to use Convert.ChangeType().

Now, I know how to solve the problem. There are lots of ways to solve it.
That is not the question. I posed the question after reading the other "Ask
a Language Designer" questions and responded to the offer to post a question
here.

The question is "Why are the default text representations for boolean
different in .Net and XML?"

Thank you for you consideration of this question.

Metro T. Sauper, Jr.
President
Sauper Associates, Inc.

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:NF**************@cpmsftngxa06.phx.gbl...

Hi,

I think the true, false in C# are the type value of C#, and it is the
mapping of .Net Framework type value. While in .Net, this type value is
True and False.
This is similiar as the int vs Int32, string vs String type mapping
relationship.

Hope this help,

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: Jon Skeet [C# MVP] <sk***@pobox.com>
| Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| Date: Fri, 24 Oct 2003 18:55:27 +0100
| Message-ID: <MP************************@msnews.microsoft.com >
| References: <O2**************@TK2MSFTNGP09.phx.gbl>
<uL**************@TK2MSFTNGP12.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: MicroPlanet Gravity v2.60
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: cpc3-rdng5-6-0-cust143.winn.cable.ntl.com
81.103.154.143
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193868 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
| > Metro, I'm not sure what you mean by the default text representation of a
| > boolean.
|
| Try this:
|
| using System;
|
| public class Test
| {
| static void Main()
| {
| Console.WriteLine (true.ToString());
| Console.WriteLine (false.ToString());
| }
| }
|
| That prints:
|
| True
| False
|
| I'm pretty sure that's what the OP was talking about.
|
| It's not C# that does this, of course, but .NET itself.
|
| --
| Jon Skeet - <sk***@pobox.com>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
|

Nov 15 '05 #7

Hi Metro,

Thanks for your feedback.
I think our discussion already shows that in C# the bool type's value are
true and false, while the bool type is mapping to the .Net Framework
Boolean type and its value are True and False.

Does this answer your question?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Metro Sauper" <ms*****@sauper.com>
| References: <O2**************@TK2MSFTNGP09.phx.gbl>
<uL**************@TK2MSFTNGP12.phx.gbl>
<MP************************@msnews.microsoft.com >
<NF**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| Date: Sat, 25 Oct 2003 01:19:47 -0400
| Lines: 111
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#C**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pcp047007pcs.trnrsv01.nj.comcast.net 68.46.19.104
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193972
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| The specific issue that brought this to mind is as follows:
|
| We are using xml to store some default configuration for reports. An xml
| entry might appear as follows:
|
| <Parameter Name="ShowDetail" Type="System.Boolean" Value="true" />
|
| Now normally with xml, we use "XmlConvert.ToBoolean(string)" to convert
| values from xml to the specific datatype, in this case boolean.
|
| However, because the datatype is defined in the entry and not predefined,
I
| wanted to use the Convert.ChangeType() method to evaluate the entry.
| Somthing like:
|
| object parameterValue =
Convert.ChanageType(node.Attributes["Value"].Value,
| System.GetType(node.Attributes[Type].Value));
|
| However, this did not work because we configured the value as "true"
rather
| than "True". So now our configuration xml has "true/false" everywhere
there
| are boolean values EXCEPT for the parameter values where the value is
| "True/False" since we use the XmlConvert for all values other than the
ones
| where we would like to use Convert.ChangeType().
|
| Now, I know how to solve the problem. There are lots of ways to solve it.
| That is not the question. I posed the question after reading the other
"Ask
| a Language Designer" questions and responded to the offer to post a
question
| here.
|
| The question is "Why are the default text representations for boolean
| different in .Net and XML?"
|
| Thank you for you consideration of this question.
|
| Metro T. Sauper, Jr.
| President
| Sauper Associates, Inc.
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:NF**************@cpmsftngxa06.phx.gbl...
| >
| > Hi,
| >
| > I think the true, false in C# are the type value of C#, and it is the
| > mapping of .Net Framework type value. While in .Net, this type value is
| > True and False.
| > This is similiar as the int vs Int32, string vs String type mapping
| > relationship.
| >
| > Hope this help,
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: Jon Skeet [C# MVP] <sk***@pobox.com>
| > | Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| > | Date: Fri, 24 Oct 2003 18:55:27 +0100
| > | Message-ID: <MP************************@msnews.microsoft.com >
| > | References: <O2**************@TK2MSFTNGP09.phx.gbl>
| > <uL**************@TK2MSFTNGP12.phx.gbl>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain; charset="iso-8859-1"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: MicroPlanet Gravity v2.60
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: cpc3-rdng5-6-0-cust143.winn.cable.ntl.com
| > 81.103.154.143
| > | Lines: 1
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:193868
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
| > | > Metro, I'm not sure what you mean by the default text representation
| of
| > a
| > | > boolean.
| > |
| > | Try this:
| > |
| > | using System;
| > |
| > | public class Test
| > | {
| > | static void Main()
| > | {
| > | Console.WriteLine (true.ToString());
| > | Console.WriteLine (false.ToString());
| > | }
| > | }
| > |
| > | That prints:
| > |
| > | True
| > | False
| > |
| > | I'm pretty sure that's what the OP was talking about.
| > |
| > | It's not C# that does this, of course, but .NET itself.
| > |
| > | --
| > | Jon Skeet - <sk***@pobox.com>
| > | http://www.pobox.com/~skeet
| > | If replying to the group, please do not mail me too
| > |
| >
|
|
|

Nov 15 '05 #8
Hi Jeffery,

Well actually no. It doesn't answer my question.

I do understand what you are saying. We realized this the moment we
encountered the problem and changed our program accordingly.

Perhaps I expected too much when posting my original question. I was
looking for someone "in the know" to explain to me why the values were
different in the first place. What the "aha!" answer was that would make me
understand why the values need to be different in the first place -- that
there was more reason than the .Net implementors flipped a coin and
"capital" 'F' and 'T' won.

There is really no reason to continue this thread. I understand the
technical aspects of the issue.

Best regards,

Metro.

--------------------------------

Metro T. Sauper, Jr.
President
Sauper Associates, Inc.
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:y2*************@cpmsftngxa06.phx.gbl...

Hi Metro,

Thanks for your feedback.
I think our discussion already shows that in C# the bool type's value are
true and false, while the bool type is mapping to the .Net Framework
Boolean type and its value are True and False.

Does this answer your question?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Metro Sauper" <ms*****@sauper.com>
| References: <O2**************@TK2MSFTNGP09.phx.gbl>
<uL**************@TK2MSFTNGP12.phx.gbl>
<MP************************@msnews.microsoft.com >
<NF**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| Date: Sat, 25 Oct 2003 01:19:47 -0400
| Lines: 111
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#C**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pcp047007pcs.trnrsv01.nj.comcast.net 68.46.19.104
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193972 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| The specific issue that brought this to mind is as follows:
|
| We are using xml to store some default configuration for reports. An xml | entry might appear as follows:
|
| <Parameter Name="ShowDetail" Type="System.Boolean" Value="true" />
|
| Now normally with xml, we use "XmlConvert.ToBoolean(string)" to convert
| values from xml to the specific datatype, in this case boolean.
|
| However, because the datatype is defined in the entry and not predefined, I
| wanted to use the Convert.ChangeType() method to evaluate the entry.
| Somthing like:
|
| object parameterValue =
Convert.ChanageType(node.Attributes["Value"].Value,
| System.GetType(node.Attributes[Type].Value));
|
| However, this did not work because we configured the value as "true"
rather
| than "True". So now our configuration xml has "true/false" everywhere
there
| are boolean values EXCEPT for the parameter values where the value is
| "True/False" since we use the XmlConvert for all values other than the
ones
| where we would like to use Convert.ChangeType().
|
| Now, I know how to solve the problem. There are lots of ways to solve it. | That is not the question. I posed the question after reading the other
"Ask
| a Language Designer" questions and responded to the offer to post a
question
| here.
|
| The question is "Why are the default text representations for boolean
| different in .Net and XML?"
|
| Thank you for you consideration of this question.
|
| Metro T. Sauper, Jr.
| President
| Sauper Associates, Inc.
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:NF**************@cpmsftngxa06.phx.gbl...
| >
| > Hi,
| >
| > I think the true, false in C# are the type value of C#, and it is the
| > mapping of .Net Framework type value. While in .Net, this type value is | > True and False.
| > This is similiar as the int vs Int32, string vs String type mapping
| > relationship.
| >
| > Hope this help,
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: Jon Skeet [C# MVP] <sk***@pobox.com>
| > | Subject: Re: Ask a Language Designer: boolean: C# vs. Xml
| > | Date: Fri, 24 Oct 2003 18:55:27 +0100
| > | Message-ID: <MP************************@msnews.microsoft.com >
| > | References: <O2**************@TK2MSFTNGP09.phx.gbl>
| > <uL**************@TK2MSFTNGP12.phx.gbl>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain; charset="iso-8859-1"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: MicroPlanet Gravity v2.60
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: cpc3-rdng5-6-0-cust143.winn.cable.ntl.com
| > 81.103.154.143
| > | Lines: 1
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:193868
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Greg Ewing [MVP] <gewing@_NO_SPAM_citidc.com> wrote:
| > | > Metro, I'm not sure what you mean by the default text representation | of
| > a
| > | > boolean.
| > |
| > | Try this:
| > |
| > | using System;
| > |
| > | public class Test
| > | {
| > | static void Main()
| > | {
| > | Console.WriteLine (true.ToString());
| > | Console.WriteLine (false.ToString());
| > | }
| > | }
| > |
| > | That prints:
| > |
| > | True
| > | False
| > |
| > | I'm pretty sure that's what the OP was talking about.
| > |
| > | It's not C# that does this, of course, but .NET itself.
| > |
| > | --
| > | Jon Skeet - <sk***@pobox.com>
| > | http://www.pobox.com/~skeet
| > | If replying to the group, please do not mail me too
| > |
| >
|
|
|

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1515
by: Andrew James | last post by:
Gentlemen, I'm currently in the process of designing a language which will be used to specify sets of files on a WebDAV server, encoded in a URL. The aims of the language are to (in no particular...
11
2234
by: PAul Maskens | last post by:
The form designer adds unnecessary code to the section when using a subclassed control. I've reproduced this in VS.NET 2002 and VS.NET 2003 so it's pretty fundamental. Outline steps: Create a...
0
920
by: Graham | last post by:
Hi everyone, I would like to create a base class which inherits from System.Windows.Forms.Form and contains several pure-virtual ("MustOverride") functions. For example: Public MustInherit...
4
3130
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
10755
by: Richard Bysouth | last post by:
Hi When attempting to view inherited forms in design mode I have been getting the message "The path is not of a legal form" and am unable to view the designer. I can't seem to find any...
0
1245
by: Bruce HS | last post by:
In VS2005, VB 2005, I suddenly can't get at a winform design view. The application still runs OK, but I can't see the designer. I'ver rebuilt the solution with no success. I'm looking for a...
5
2920
by: Alan T | last post by:
I got this kind of error recently: When I tried to open a form I got error something like this: One of more errors encountered while loading the designer. The errors are listed below. Some...
5
1490
by: active | last post by:
I tried to use a datasource with a combobox and it didn't work completely so I build a small test that was much more straight forward then the app. The test was to see if the combobox dropdown...
4
1666
by: DanThMan | last post by:
The following code works when I debug and when I install the software and run the .exe, but if I try to open the form in the designer (which causes this code to run), I get an error: Private Sub...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6991
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
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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
4673
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.