473,408 Members | 1,821 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,408 software developers and data experts.

display boolean as Yes/No

Is there a way to change the output of the ToString function for a boolean
variable to display Yes/No?

Thanks,
Eric
Nov 15 '05 #1
3 5218
IFormatProvider?

"Eric Gurney" <eg*****@removethis.yahoo.com> wrote in message
news:uV**************@tk2msftngp13.phx.gbl...
Is there a way to change the output of the ToString function for a boolean
variable to display Yes/No?

Thanks,
Eric

Nov 15 '05 #2
From: "Eric Gurney" <eg*****@removethis.yahoo.com>

| Is there a way to change the output of the ToString function for a boolean
| variable to display Yes/No?

To change the behavior of a type, you have to change its source code.
Since bool is a built-in type, you cannot change its behavior.

The easiest thing to do is to have something like:

public static string BoolToYesNo( bool b ) { return b ? "Yes" : "No"; }

You can put this method inside one of your utility classes.

Another way is to define your own boolean type whose ToString() method
return "Yes" or "No". If you go down this path, you can choose to
implement the IFormattable interface and have more formatting options.

- Zhanyong Wan

Visual Studio and .NET Setup

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included samples (if any) is subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 15 '05 #3
That's pretty much what I was going to do. I was looking for a more elegant
solution but I guess this works.
Why didn't MSFT allow the IFormatProvider interface to be used with the bool
type?

"Zhanyong Wan [MSFT]" <zh****@online.microsoft.com> wrote in message
news:Fu**************@cpmsftngxa07.phx.gbl...
From: "Eric Gurney" <eg*****@removethis.yahoo.com>

| Is there a way to change the output of the ToString function for a boolean | variable to display Yes/No?

To change the behavior of a type, you have to change its source code.
Since bool is a built-in type, you cannot change its behavior.

The easiest thing to do is to have something like:

public static string BoolToYesNo( bool b ) { return b ? "Yes" : "No"; }
You can put this method inside one of your utility classes.

Another way is to define your own boolean type whose ToString() method
return "Yes" or "No". If you go down this path, you can choose to
implement the IFormattable interface and have more formatting options.

- Zhanyong Wan

Visual Studio and .NET Setup

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included samples (if any) is subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 15 '05 #4

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

Similar topics

2
by: DraguVaso | last post by:
Hi, In the override of the Paint-method of a DataGridTextBoxColumn I want to show an image with BitBlt, to see what I can gain there on performance. The problem is: It doesn't show me the image...
3
by: dickster | last post by:
A general query Im serialising a person object with the following member variables Class Person Private _forenames As String Private _surname As String Private _dob As Date Private...
4
by: Patrick.O.Ige | last post by:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected when the page is loaded depending on a Boolean value from the Database.. chkDebtor.DataSource = objDR...
4
by: Mike L | last post by:
Error occurs on "System.Deployment.Application.ApplicationDeployment.CurrentDeployment" ** Here is my code private void frmMain_Load(object sender, System.EventArgs e) {...
2
by: Lou | last post by:
I have a class that creates an instance of the seril Port. Every thing works fine except whenever I receive data I cannot display the recieved data. I get no errors but the recived data seems to...
13
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log...
2
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
2
by: Lucas | last post by:
Hi, I want to display an exception in a javascript alert and I'm rendering that client code using ClientScript.RegisterStartupScript(GetType(), key,...
4
by: Yitzak | last post by:
Have a query that is arregated into crosstab query, it is working correctly. select Yes as selected from tblname or select true as selected from tblname Produces -1 ( vba value of True) in...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
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
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
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
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.