當前位置: 首頁>>代碼示例>>C#>>正文


C# Coordinate.SetDMS方法代碼示例

本文整理匯總了C#中System.Coordinate.SetDMS方法的典型用法代碼示例。如果您正苦於以下問題:C# Coordinate.SetDMS方法的具體用法?C# Coordinate.SetDMS怎麽用?C# Coordinate.SetDMS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Coordinate的用法示例。


在下文中一共展示了Coordinate.SetDMS方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main()
        {
            // Create a new coordinate with some values
            Coordinate c = new Coordinate();
            c.SetDMS(00, 10, 20.8f, true, 30, 40, 50.9f, false);

            // Create a new coordinate list with
            CoordinateList cl = new CoordinateList();
            cl.Add(new Coordinate( 1.0f, 1.0f));
            cl.Add(new Coordinate(-2.4f, 1.5f));
            cl.Add(new Coordinate(-3.7f, 2.2f));
            cl.Add(new Coordinate(-2.0f, -.5f));

            // Show formatting capabilities
            MessageBox.Show(
                string.Format("String Formatting:\r\nD: {0:D}\r\nDM: {0:DM}\r\nDMS: {0:DMS}\r\nISO: {0:ISO}", c),
                "Formatting example");

            // Serialize coordinates to a string object
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter sw = new System.IO.StringWriter(sb);
            string part1, part2;

            // Single coordinate
            System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(Coordinate));
            xs.Serialize(sw, c);
            sw.Flush();
            part1 = sb.ToString();

            // Coordinate list
            sb.Length = 0;
            System.Xml.Serialization.XmlSerializer xsl = new System.Xml.Serialization.XmlSerializer(typeof(CoordinateList));
            xsl.Serialize(sw, cl);
            sw.Flush();
            part2 = sb.ToString();

            sw.Close();

            // Show serialized data
            MessageBox.Show(string.Format("Single coordinate:\r\n{0}\r\n\r\nCoordinate list:\r\n{1}", part1, part2),
                "Serialization example");

            // Deserialize single coordinate from a string object
            System.IO.StringReader sr = new System.IO.StringReader(part1);
            Coordinate c1 = (Coordinate)xs.Deserialize(sr);
            sr.Close();

            // Deserialize coordinate list from a string object
            sr = new System.IO.StringReader(part2);
            CoordinateList cl1 = (CoordinateList)xsl.Deserialize(sr);
            sr.Close();

            // Show properties of deserialized data
            string message = string.Format(
                "Single coordinate:\r\n{0}\r\nLatitude: {1}°\r\nLongitude: {2}°\r\n\r\nCoordinate list:\r\n",
                c1, c1.Latitude, c1.Longitude);
            foreach (Coordinate coord in cl1)
                message += coord.ToString() + "\r\n";

            MessageBox.Show(message, "Deserialization example");
        }
開發者ID:jaime-olivares,項目名稱:coordinate,代碼行數:61,代碼來源:Program.cs


注:本文中的System.Coordinate.SetDMS方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。