Click here to Skip to main content
15,041,266 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: (untagged)
How can we prevent negative integers in an array code?
Posted
Updated 28-Oct-14 6:47am
v3
Comments
Sergey Alexandrovich Kryukov 28-Oct-14 12:30pm
   
By not putting them? What's the problem?
—SA
CPallini 28-Oct-14 12:32pm
   
Could you please detail your scenario?
PIEBALDconsult 28-Oct-14 12:51pm
   
We don't use arrays anymore; we use Lists. But you can use an unsigned datatype as Mehdi said. Or derive your own List that performs a test.
Sergey Alexandrovich Kryukov 28-Oct-14 13:24pm
   
Who "we"? I personally use both and find arrays important... :-)
—SA

1 solution

Define your data type to be unsigned i.e. uint ulong etc.
   
Comments
Sergey Alexandrovich Kryukov 28-Oct-14 13:22pm
   
It would be the best idea, of course, but we just don't know exactly. Maybe an array needs to be populated with some positive values from UI and then the values can be changed. Not likely but possible. It's safer to say that the question makes no sense until it is clarified.
—SA
Mehdi Gholam 29-Oct-14 2:28am
   
Exactly!

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