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


C# Matrix.ToString方法代码示例

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


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

示例1: Main

        static void Main()
        {
            int row = 4, col = 5;
            var matrixOne = new Matrix<int>(row, col);
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    matrixOne[r, c] = r + c;
                }
            }

            Console.WriteLine("Matrix One:");
            Console.WriteLine(matrixOne.ToString());

            var matrixTwo = new Matrix<int>(row, col);
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    matrixTwo[r, c] = (r + c) * 2;
                }
            }

            Console.WriteLine("Second matrix:");
            Console.WriteLine(matrixOne.ToString());

            var sum = matrixOne + matrixTwo;
            Console.WriteLine($"Sum: \n{sum.ToString()}");
            var minus = matrixOne - matrixTwo;
            Console.WriteLine($"Minus:\n {minus.ToString()}");
            var multy = matrixOne * matrixTwo;
            Console.WriteLine($"Multy: \n{multy.ToString()}");
        }
开发者ID:deskuuu,项目名称:TelerikAcademy,代码行数:34,代码来源:TestMatrix.cs

示例2: DumpMatrixString

 public static string DumpMatrixString(Matrix matrix)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("==");
     Label_0076:
     builder.Append(matrix.ToString());
     builder.Append("==\n");
     int num = 0;
     Label_001E:
     if (num < matrix.Rows)
     {
         builder.Append("  [");
         for (int i = 0; i < matrix.Cols; i++)
         {
             if (i != 0)
             {
                 builder.Append(",");
             }
             builder.Append(matrix[num, i]);
         }
     }
     else
     {
         return builder.ToString();
     }
     if (0 == 0)
     {
         builder.Append("]\n");
         num++;
         goto Label_001E;
     }
     goto Label_0076;
 }
开发者ID:neismit,项目名称:emds,代码行数:33,代码来源:DumpMatrix.cs

示例3: Main

        static void Main(string[] args)
        {
            //Create two matrices
            Matrix<int> mat1 = new Matrix<int>(3, 5);
            Matrix<int> mat2 = new Matrix<int>(3, 5);

            //Fill the matrices with numbers
            for (int i = 0; i < mat1.Rows; i++)
            {
                for (int j = 0; j < mat1.Cols; j++)
                {
                    mat1.AddNumber(i + j, i, j);
                }
            }
            for (int i = 0; i < mat1.Rows; i++)
            {
                for (int j = 0; j < mat1.Cols; j++)
                {
                    mat2[i, j] = i + j;
                }
            }

            //Print them
            Console.WriteLine(mat1.ToString());
            Console.WriteLine(mat2.ToString());

            //Use predefined operators and print the result
            Console.WriteLine((mat1 + mat2).ToString());
            Console.WriteLine((mat1 - mat2).ToString());
            //Console.WriteLine((mat2*mat2).ToString()); //For multiplication we need the row on the first matrix and col on the second matrix to be equal
            Console.WriteLine(mat1==mat2);
        }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:32,代码来源:Program.cs

示例4: Main

        static void Main()
        {
            //create instance of matixT
            Matrix<int> matrix1 = new Matrix<int>(3, 3);
            Matrix<int> matrix2 = new Matrix<int>(3, 3);

            //Fill in with numbers
            for (int i = 0; i < matrix1.Rows; i++)
            {
                for (int j = 0; j < matrix1.Cols; j++)
                {
                    matrix1.AddNumber(i + j, i, j);
                }
            }
            for (int i = 0; i < matrix1.Rows; i++)
            {
                for (int j = 0; j < matrix1.Cols; j++)
                {
                    matrix2[i, j] = i + j;
                }
            }

            //Print to view the starting point
            Console.WriteLine(matrix1.ToString());
            Console.WriteLine(matrix2.ToString());

            //test operators
            Console.WriteLine("operator + :");
            Console.WriteLine((matrix1 + matrix2).ToString());
            Console.WriteLine("operator - :");
            Console.WriteLine((matrix1 - matrix2).ToString());

            //check for equality
            Console.WriteLine(matrix1 == matrix2);
        }
开发者ID:kicata,项目名称:OPP,代码行数:35,代码来源:TestMatrixT.cs

示例5: TwoSizedMatrixTest

        public void TwoSizedMatrixTest()
        {
            Matrix matrix = new Matrix(2);

            Assert.IsTrue(matrix.ToString() == string.Format("    1    4\r\n"+
                                                             "    3    2"));
        }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:7,代码来源:Tests.cs

示例6: Main

        static void Main()
        {
            Matrix<int> testMatrix1 = new Matrix<int>(new int[2,3]{{1,2,3},{4,5,6}});
            Matrix<int> testMatrix2 = new Matrix<int>(new int[3,2] { {7,8}, {9,10},{11,12} });
            Matrix<int> testMatrix3 = new Matrix<int>(new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, {7,8,9}});
            Matrix<int> testMatrix4 = new Matrix<int>(new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, {7,8,9} });

            //Multiply
            Console.WriteLine("Matrix 1:");
            Console.WriteLine(testMatrix1.ToString());

            Console.WriteLine("Matrix 2:");
            Console.WriteLine(testMatrix2.ToString());
            Console.WriteLine("Multiplication:");
            Console.WriteLine((testMatrix1 * testMatrix2).ToString());

            //Addition/ Substraction
            Console.WriteLine("Matrix 3:");
            Console.WriteLine(testMatrix3.ToString());

            Console.WriteLine("Matrix 4:");
            Console.WriteLine(testMatrix4.ToString());

            Console.WriteLine("Addition Matrix 3 + Matrix4:");
            Console.WriteLine((testMatrix3 + testMatrix4).ToString());

            Console.WriteLine("Substraction MAtrix3 - Matrix4:");
            Console.WriteLine((testMatrix3 - testMatrix4).ToString());

            //Indexer
            Console.WriteLine("Matrix3[2,2]:{0}",testMatrix3[2,2]);
        }
开发者ID:melliemello,项目名称:TelerikAcademyHomeworks,代码行数:32,代码来源:Program.cs

示例7: GetPresence

        public Presence[] GetPresence(string from, string to, Matrix.Xmpp.PresenceType? type, bool remove)
        {
            List<Presence> presences = new List<Presence>();
            var db = GetDatabase();
            var collection = db.GetCollection("offline_presence");
            var query = new QueryDocument();
            if (from != null)
                query.Add("from", from);
            if (to != null)
                query.Add("to", to);
            if (type != null)
                query.Add("type", type.ToString());

            MongoCursor<BsonDocument> cursor;
            if (from == null && to == null)
                cursor = collection.FindAll();
            else
                cursor = collection.Find(query);

            foreach (var item in cursor)
            {
                Presence presence = (Presence)Presence.LoadXml(item.GetValue("value").AsString);
                presences.Add(presence);
            }
            if (remove)
                collection.Remove(query);
            return presences.ToArray();
        }
开发者ID:yuechuanbingzhi163,项目名称:GJTalk,代码行数:28,代码来源:OfflineMessageManager.cs

示例8: TestMatrixToString

 public void TestMatrixToString()
 {
     Matrix matrix = new Matrix(2);
     string expected = string.Format(
         "  1  4" + Environment.NewLine +
         "  3  2" + Environment.NewLine);
     Assert.AreEqual(expected, matrix.ToString());
 }
开发者ID:dchakov,项目名称:High-Quality-Code-HomeWork,代码行数:8,代码来源:WalkInMatrixTest.cs

示例9: Main

        static void Main(string[] args)
        {
            Matrix<int> test = new Matrix<int>(2, 2);
            test.GetCol(3);
            
            Console.WriteLine(test.ToString());

        }
开发者ID:Alex-Bubblemaster,项目名称:C-Sharp-OOP,代码行数:8,代码来源:TestWithMain.cs

示例10: ThreeSizedMatrixTest

        public void ThreeSizedMatrixTest()
        {
            Matrix matrix = new Matrix(3);

            Assert.IsTrue(matrix.ToString() == string.Format("    1    7    8\r\n" +
                                                             "    6    2    9\r\n" +
                                                             "    5    4    3"));
        }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:8,代码来源:Tests.cs

示例11: TestMatrixToString

        public void TestMatrixToString()
        {
            Matrix matrix = new Matrix(3);

            string expected = "0 0 0\n0 0 0\n0 0 0\n";
            string actual = matrix.ToString();

            Assert.AreEqual(expected, actual);
        }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:9,代码来源:MatrixTests.cs

示例12: Main

        static void Main()
        {
            // Creating two matrices to be tested
            Matrix<int> firstMatrix = new Matrix<int>(3, 4);
            Console.WriteLine("First Matrix Capacity is {0}\n", firstMatrix.Capacity);

            Matrix<int> secondMatrix = new Matrix<int>(3, 4);

            FillMatrixWithInt(firstMatrix);
            Console.WriteLine("First Matrix:");
            Console.WriteLine(firstMatrix.ToString());

            FillMatrixWithInt(secondMatrix);
            Console.WriteLine("Second Matrix:");
            Console.WriteLine(secondMatrix.ToString());

            // test operator +
            firstMatrix += secondMatrix;
            Console.WriteLine("Applying the operator +");
            Console.WriteLine(firstMatrix.ToString());

            // test operator -
            firstMatrix -= secondMatrix;
            Console.WriteLine("Applying the operator -");
            Console.WriteLine(firstMatrix.ToString());

            // test operator *
            firstMatrix *= secondMatrix;
            Console.WriteLine("Applying the operator *");
            Console.WriteLine(firstMatrix.ToString());

            // test method bool
            Matrix<double> testBool = new Matrix<double>(1, 1);
            testBool[0, 0] = 0.0;
            if (testBool)
            {
                Console.WriteLine("testBool does not contain Zero");
            }
            else
            {
                Console.WriteLine("testBool contains Zero");
            }
            Console.WriteLine();
        }
开发者ID:tddold,项目名称:TelerikAcademyHomework,代码行数:44,代码来源:TestMatrix.cs

示例13: Main

        static void Main(string[] args)
        {
            Matrix<int> matrix1 = new Matrix<int>(5, 5);
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    matrix1[i, j] = i * j;
                }
            }

            Matrix<int> matrix2 = new Matrix<int>(5, 5);
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    matrix2[i, j] = i * j;
                }
            }

            int el = matrix1[2, 2];
            Console.WriteLine("matrix1[2, 2]: {0}", el);
            Console.WriteLine("matrix1:");
            Console.WriteLine(matrix1.ToString());
            Console.WriteLine("matrix2: ");
            Console.WriteLine(matrix2.ToString());

            Matrix<int> matrixMultiplied = new Matrix<int>(5, 5);
            matrixMultiplied = matrix1 * matrix2;
            Console.WriteLine("matrix1 * matrix2:");
            Console.WriteLine(matrixMultiplied.ToString());

            Matrix<int> matrixAddition = new Matrix<int>(5, 5);
            matrixAddition = matrix1 + matrix2;
            Console.WriteLine("matrix1 + matrix2:");
            Console.WriteLine(matrixAddition.ToString());

            Matrix<int> matrixSubtract = new Matrix<int>(5, 5);
            matrixAddition = matrix1 + matrix2;
            Console.WriteLine("matrix1 - matrix2:");
            Console.WriteLine(matrixSubtract.ToString());

            Matrix<int> m = new Matrix<int>(2, 2);
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    m[i, j] = 1;
                }
            }
            if (m)
            {
                Console.WriteLine("m have no element with value 0");
            }
        }
开发者ID:Tsvetomir-Kirchev,项目名称:Telerik-Academy-Exercises,代码行数:55,代码来源:Program.cs

示例14: SixSizedMatrixTest

        public void SixSizedMatrixTest()
        {
            Matrix matrix = new Matrix(6);

            Assert.IsTrue(matrix.ToString() == string.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}",
                "    1   16   17   18   19   20",
                "   15    2   27   28   29   21",
                "   14   31    3   26   30   22",
                "   13   36   32    4   25   23",
                "   12   35   34   33    5   24",
                "   11   10    9    8    7    6"));
        }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:12,代码来源:Tests.cs

示例15: Main

 static void Main()
 {
     Matrix<double> test = new Matrix<double>(2, 2);
     test[1, 1] = 2.4;
     Console.WriteLine(test.ToString());
     Matrix<string> anotherTest = new Matrix<string>(3, 3);
     anotherTest[0, 0] = "The";
     anotherTest[1, 0] = "has";
     anotherTest[0, 1] = "Matrix";
     anotherTest[1, 1] = "you";
     Console.WriteLine(anotherTest.ToString());
 }
开发者ID:Alex-Bubblemaster,项目名称:C-Sharp-OOP,代码行数:12,代码来源:TestTheMatrix.cs


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