473,545 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enumeration Format Strings. Difference between g and f?

Can someone give me an example where an enumeration format string of g would
return a different result to that of f?

http://msdn.microsoft.com/library/de...pguide/html/cp
conenumerationf ormatstrings.as p

--

Jul 21 '05 #1
2 5062
John,
Can someone give me an example where an enumeration format string of g would
return a different result to that of f?


enum E
{
A = 0x1,
B = 0x2,
}

E e3 = (E)3;
Console.WriteLi ne( e3.ToString( "g" ) );
Console.WriteLi ne( e3.ToString( "f" ) );

"g" will print 3, "f" will print A, B. The f specifier gives you flags
formatting, even if the Flags attribute hasn't been applied to the
enum type.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 21 '05 #2
> -------------------------------------------------
Mattias Sjögren wrote (at this indent level):
-------------------------------------------------

Can someone give me an example where an enumeration format string of
g would return a different result to that of f?


enum E
{
A = 0x1,
B = 0x2,
}

E e3 = (E)3;
Console.WriteLi ne( e3.ToString( "g" ) );
Console.WriteLi ne( e3.ToString( "f" ) );

"g" will print 3, "f" will print A, B. The f specifier gives you flags
formatting, even if the Flags attribute hasn't been applied to the
enum type.


Thanks Mattias. I can now see the difference. Interestingly if you change

E e3 = (E)3; //to
E e3 = (E)1;

You get A for both cases.

Jul 21 '05 #3

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

Similar topics

3
2152
by: Lowell Kirsh | last post by:
In Peter Norvig's Infrequently Answered Questions he explains that the following 2 fnctions look almost identical but are not the same: def printf(format, *args): print format % args, def printf(format, *args): print str(format) % args, The only difference is that in the second one, str(format) replaces format. If args are not given and...
15
42982
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our...
1
3655
by: Sergey Poberezovskiy | last post by:
Hi, I have a simple enumeration in my schema: <xs:element name="el_1"> <xs:simpleType> <xs:restiction base="xs:string"> <xs:enumeration value="value and space 1"/> <xs:enumeration value="value2 with spaces"/> ...
7
12686
by: archway | last post by:
I know you cannot have string enumerations such as: enum myStringEnum { enumItem1 = "value 1", enumItem2 = "value 2", etc } However, I was wondering whether you had ever created something that would mimic this? I have tried the following:
3
10616
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am after. Create a class named “clsMyItems” and in that class place an enum. Public Enum Items Item1 = 0 Item2 = 1 Item3 = 2
2
251
by: John Bentley | last post by:
Can someone give me an example where an enumeration format string of g would return a different result to that of f? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp conenumerationformatstrings.asp --
27
2645
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to provide a "one obvious way" to do enumerations in Python. > >>> from enum import Enum > >>> day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
3
4775
by: muler | last post by:
hi all, After reading this excerpt from "The C# Programming Language", (By Anders) I tried to check it out. Unfortunately, I'm getting compile errors. Can anyone illustrate this with an example: ---------------------------------------------------- Section 7.7.4 - enumeration addition
3
1364
by: DotNetNewbie | last post by:
Hi, I want to create a method that takes in the type of a Enumeration, passes in the Enumeration as an object, and then outputs the values with checkboxes, and pre-checks the checkbox if that value is set in a mask. This is what I have so far that outputs the values as a checkbox, but I need to pass in *any* mask so it can check if that...
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7757
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4945
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
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 we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.