当前位置: 首页>>代码示例>>C#>>正文


C# Double.SetValue方法代码示例

本文整理汇总了C#中System.Double.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Double.SetValue方法的具体用法?C# Double.SetValue怎么用?C# Double.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Double的用法示例。


在下文中一共展示了Double.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: diamond

        private void diamond( HeightMap map, Int32 x, Int32 y, Int32 pass )
        {
            Double[] points = new Double[]{};
            Int32 i = 0;

            // NW
            points.SetValue(
                map.getPoint( x, y ),
                i
            );
            i++;

            //NE
            try
            {
                points.SetValue(
                    map.getPoint(
                        x + pass,
                        y
                    ),
                    i
                );
                i++;
            }
            catch( IndexOutOfRangeException ) { }

            //SW
            try
            {
                points.SetValue(
                    map.getPoint(
                        x,
                        y + pass
                    ),
                    i
                );
                i++;
            }
            catch( IndexOutOfRangeException ) { }

            //SE
            try
            {
                points.SetValue(
                    map.getPoint(
                        x + pass,
                        y + pass
                    ),
                    i
                );
                i++;
            }
            catch( IndexOutOfRangeException ) { }

            // Center
            this.alterMidpoint(
                map,
                x + pass >> 1,
                y + pass >> 1,
                points
            );
        }
开发者ID:kevinpeno,项目名称:TerraGen,代码行数:62,代码来源:DiamondSquareGenerator.cs

示例2: Main

        static void Main(string[] args)
        {
            /*
             * The object of this program is to ask the user to enter 7 grades for tests
             * and then the program will sum those grades and average them.
             */

            //Declare and initialize variables
            Double dSum = 0.0;
            Double dAvg = 0.0;
            Double[] dGrades;
            String[] sNames;
            String sUserResp = String.Empty;
            Int32 iStudentCount = 0;

            //Determine number of students to have test scores
            Console.Write("How many students in the class? ");
            sUserResp = Console.ReadLine();
            try
            {
                iStudentCount = Convert.ToInt32(sUserResp);
            }
            catch(Exception ex)
            {
                Console.WriteLine("I beg your pardon, fool. You have entered invalid data.");
                Console.WriteLine(ex.Message);
                Pause("Program will now exit.");
                return;
            }

            dGrades = new Double[iStudentCount];
            sNames = new String[iStudentCount];

            Type arrayType = dGrades.GetType();
            if (arrayType.IsArray)
            {
                Pause("dGrades is an array of " + arrayType.ToString());
            }
            else
            {
                Pause("dGrades is NOT an array.");
            }
            //Start loop for data entry
            for (Int32 i = 0; i < iStudentCount; i++)
            {
                //Obtain a student name
                Console.Write("Enter a name for student #" + (i + 1).ToString() + ": ");
                sNames.SetValue(Console.ReadLine(), i);

                //Obtain that student's grade
                Console.Write("Enter a grade for student #" + (i + 1).ToString() + ": ");
                sUserResp = Console.ReadLine();
                try
                {
                    dGrades.SetValue(Convert.ToDouble(sUserResp), i);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("I beg your pardon, fool. You have entered invalid data.");
                    Console.WriteLine(ex.Message);
                    Pause("Program will now exit.");
                    return;
                }

                //Add this grade to the running sum
                dSum += dGrades[i];

            }
            //Average the grades
            dAvg = dSum / (Double)iStudentCount;

            Console.WriteLine("\nHere is the breakdown of our student grades:");
            for (Int32 i = 0; i < iStudentCount; i++)
            {
                Console.Write(sNames.GetValue(i) + ": ");
                Console.WriteLine(dGrades.GetValue(i).ToString());
            }

            //Output the average
            Pause("The average score is: " + dAvg.ToString() +
                ".\nProgram will now exit.");
        }
开发者ID:Everex210,项目名称:ConsoleArrayPractice,代码行数:82,代码来源:Program.cs


注:本文中的System.Double.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。