Function comaparison

May 29 2014 12:40 AM
I need to split the count exactly into 9 partitions if contains any remainder it should be appended to last partition. I have created two functions ideally both are same.Kindly suggest which will be the best way to implement and why.



Function 1
public static int trustcheck(int totalRows, int rowCount)
        {
            if (rowCount != 0 && (rowCount % (totalRows / 9)).Equals(0))
            {
                if (((totalRows % (totalRows / 9)) + rowCount).Equals(totalRows))
                {
                    return 0;
                }
                else
                {
                    return 1;
                }
            }
            else
            {
                if (rowCount.Equals(totalRows))
                    return 1;
                else
                    return 0;
            }


        }
Function2

        public static int trustcheck2(int totalRows, int rowCount)
        {
            return (rowCount != 0 && (rowCount % (totalRows / 9)).Equals(0)) ? (((totalRows % (totalRows / 9)) + rowCount).Equals(totalRows) ? 0 : 1) : ((rowCount.Equals(totalRows)) ? 1 : 0);

        }


Main Method
static void Main(string[] args)
        {
            trustcheck(105, 105);
            ArrayList lst = new ArrayList();
            for (int k = 0; k <= 105; k++)
            {
                if (trustcheck2(105, k) > 0)
                {
                    lst.Add(k);
                }
            }
}

Answers (4)