Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by hdav · Jul 29, 2016 at 04:03 AM · numbers

How do I find the highest integer in a list of values?

Im making a card game with C# and each card is 4 values which can change based on other cards played and I want to find the highest value of the 4 then compare the highest one against another varying integer but have no clue how to do any of it.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by 5c4r3cr0w · Jul 29, 2016 at 04:49 AM

Here is simplest code to find highest number from list

     public List<int> list = new List<int> ();
 
        int GetMax(){
                 list.Sort ();
         int max = list [list.Count - 1];
         return max;
        }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hdav · Aug 01, 2016 at 02:13 AM 0
Share

Could you explain the code in further detail, I'm not sure if I understand it.

Is it like

    public List<int> Card = new List ( );

         int Get$$anonymous$$ax ( ) {
               Card.sort ( );
         int max = Card [Card.Count - 1];
         return max;
         }

or something different?

avatar image 5c4r3cr0w hdav · Aug 03, 2016 at 12:34 PM 0
Share

Yes. you got this right. But let me still explain. You can add any number of cards in your list. Here card is your list.

Now sort() function arranges numbers in ascending order so the after calling Card.sort() largest value would be at last index of list. so Card[ Card.Count - 1] will be the largest number.

Now you need to call Get$$anonymous$$ax() in order to get this value like :

 int $$anonymous$$axNumber = Get$$anonymous$$ax();
avatar image hdav 5c4r3cr0w · Aug 04, 2016 at 12:33 AM 0
Share

Thanks!

Also I have questions about other parts of this card game and I'm wondering if you can answer them?

First off is that in my game thiers field card and effect cards that affect the integers in the list by adding and subtracting from them depending on which one is used and I was wondering what the is the easiest way to incorporate that into this script

        public int fire;
        public int water;
        public int air;
        public int earth;

        private int f;
        private int w;
        private int a;
        private int e;

        void start ( ) {
             f = fire;
            w = water;
            a = air;
            e = earth;

      void restart ( ) {
            fire = f;
            water = w;
            air = a;
            earth = e;

And also I have no clue how to make a customizable deck and also how to make it so that it deals cards in random order but never deals the same card twice into the hand at any given time.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Money-system for decillionare game 1 Answer

Add "1" to score text? Not "11111"? 1 Answer

how can i check if two numbers are close to each other? 1 Answer

Using very big Numbers 0 Answers

how can i access list of sprites in my code ?? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges