Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi there, is there a way i can make my system accept char[] values like '-' in the form of an int value.

I have an int place holder, but when there is no int value supplied, i want to put '-' in that place of the int. Is this really possible?


Thanks in advance
Martin
Posted
Comments
OriginalGriff 17-Jul-11 3:47am    
Sorry? Do you want to give us an example so we can understand better what you are trying to achieve?

no this is not posible to do. one thing you could do is make you int nullable and then if the int is null then use display the value "-".

C#
int? myIntValue = null;
        public string GetIntValue()
        {
            return myIntValue.HasValue ? myIntValue.Value.ToString() : "-";
        }


Hope this helps
 
Share this answer
 
int specialValue = '-';

specialValue will now contain the numeric equivalent of the '-' character which is hex 0x2D or decimal 45.
 
Share this answer
 
You can use nullable types as an int.
When there is no value supplied, set the int variable to null, and then while displaying the null, show a '-'.
e.g.
int? i = null;
Console.WriteLine(i==null?"-":i.ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900