{"id":2215,"date":"2011-05-06T14:51:25","date_gmt":"2011-05-06T05:51:25","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=2215"},"modified":"2011-05-06T14:51:25","modified_gmt":"2011-05-06T05:51:25","slug":"string-%e3%81%b8%e3%81%ae%e3%82%ad%e3%83%a3%e3%82%b9%e3%83%88%e3%81%a8-tostring-%e3%81%ae%e5%8b%95%e4%bd%9c%e3%81%af%e7%95%b0%e3%81%aa%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/2215","title":{"rendered":"string \u3078\u306e\u30ad\u30e3\u30b9\u30c8\u3068 ToString \u306e\u52d5\u4f5c\u306f\u7570\u306a\u308b"},"content":{"rendered":"<p>\u3044\u3064\u307e\u3067\u3082\u5371\u306a\u3044\uff08\uff1f\uff09PDF\u3092\u6652\u3057\u3066\u304a\u304f\u308f\u3051\u306b\u306f\u884c\u304b\u306a\u3044\u306e\u3067\uff57\u3001\u5c0f\u30cd\u30bf\u3067\u30d6\u30ed\u30b0\u3092\u9032\u3081\u307e\u3059\u3002<\/p>\n<p>\u6642\u3005(\u7279\u306bVB\u30d7\u30ed\u30b0\u30e9\u30de\u306e\u65b9\uff1f)\u3067\u306f\u3001\u6587\u5b57\u5217\u3078\u306e\u30ad\u30e3\u30b9\u30c8\u3092 ToString \u3067\u884c\u3063\u3066\u3044\u308b\u7b87\u6240\u3092\u898b\u639b\u3051\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u5371\u3046\u3044\u3067\u3059\u3001\u3068\u3044\u3046\u8a71\u3067\u3059\u306d\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u8aad\u307f\u8fbc\u307f\u3092\u3057\u305f\u6642\u306b VB \u3060\u3068\u3001\u3053\u3046\u3044\u3046\u98a8\u306b\u66f8\u3044\u3066\u3044\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim da as new SqlDataAdapter(&amp;quot;SELECT * ...&amp;quot;, cn )\r\nDim dt as new DataTable\r\nda.Fill(dt)\r\n&#039; \u6587\u5b57\u5217\u3092\u53d6\u308a\u51fa\u3059\r\ndim name as String = &amp;quot;&amp;quot;\r\nif dt.Rows.Count &gt; 0 then\r\n  name = dt.Rows(0)(&amp;quot;name&amp;quot;).ToString()\r\nend if\r\n<\/pre>\n<p>\u3053\u3093\u306a\u98a8\u306b\u3001ToString \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066 object \u578b\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305f\u3060\u3057\u3001\u672c\u6765\u306f\u3053\u3053\u306f\u30ad\u30e3\u30b9\u30c8\u3092\u4f7f\u3046\u3079\u304d\u3067\u3059\u3002\u5f8c\u8ff0\u3057\u307e\u3059\u304c\u3001\u30ad\u30e3\u30b9\u30c8\u3068 ToString \u30e1\u30bd\u30c3\u30c9\u306e\u3010\u610f\u5473\u3011\u304c\u7570\u306a\u308b\u306e\u3067\u3001\u5fc5\u305a\u3057\u3082\u540c\u3058\u52d5\u4f5c\u3092\u3059\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u306e\u305f\u3081\u3067\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\ndim name as string = CType( dt.Rows(0)(&quot;name&quot;), String )\r\n<\/pre>\n<p>C# \u306e\u5834\u5408\u306f\u3001<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nstring name = (string)dt.Rows&#x5B;0]&#x5B;&quot;name&quot;];\r\n<\/pre>\n<p># \u8a73\u7d30\u306b\u8a00\u3048\u3070\u3001dynamic cast \u3092\u4f7f\u3046\u3093\u3067\u3057\u3087\u3046\u304c\u3001\u3053\u3053\u3067\u306f\u666e\u901a\u306e\u30ad\u30e3\u30b9\u30c8\u3067\u3002<\/p>\n<p>\u3055\u3066\u3001ToString \u3067\u3082\u7528\u9014\u306f\u8db3\u308a\u308b\u306e\u3067\u3001\u3053\u308c\u3067\u3082\u826f\u3044\u3088\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\u3001\u4f55\u6545\u30ad\u30e3\u30b9\u30c8\u3092\u4f7f\u308f\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u304b\u3068\u3044\u3046\u3068\u3001\u4ee5\u4e0b\u306e\u7406\u7531\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\ndim name As String = obj.ToString()\r\n<\/pre>\n<p>\u3068\u3057\u305f\u6642\u306b\u3001name \u306b\u306f\u5fc5\u305a\u671f\u5f85\u3059\u308b\u3010\u6587\u5b57\u5217\u3011\u304c\u5165\u308b\u304b\u3068\u3044\u3046\u3068\u3001\u5b9f\u306f\u7570\u306a\u308b\u306e\u3067\u3059\u3002\u3053\u308c\u306f\u3001ListBox \u3092\u6271\u3046\u3068\u5206\u304b\u308b\u306e\u3067\u3059\u304c\u3001ToString \u30e1\u30bd\u30c3\u30c9\u306f\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u53ef\u80fd\u306a\u306e\u3067\u3001\u5358\u7d14\u306a\u30ad\u30e3\u30b9\u30c8\u3068\u306f\u7570\u306a\u308b\u5024\u3092\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<p>\u52d5\u4f5c\u304c\u5206\u304b\u308b\u3088\u3046\u306b\u6975\u7aef\u306a\u4f8b\u3092\u793a\u3059\u3068\u3001<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPublic Class AClass\r\n    Public Shadows Function ToString() As String\r\n        Return &quot;ToString AClass&quot;\r\n    End Function\r\n\r\n    Public Shared Narrowing Operator CType(ByVal b As AClass) As String\r\n        Return &quot;Cast AClass&quot;\r\n    End Operator\r\nEnd Class\r\n<\/pre>\n<p>ToString \u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u305f\u3082\u306e\u3068\u3001\u30ad\u30e3\u30b9\u30c8\u3092\u518d\u5b9a\u7fa9\u3057\u305f\u3082\u306e\u3092\u7528\u610f\u3057\u307e\u3059\u3002<br \/>\n\u3059\u308b\u3068\u6b21\u306e\u30b3\u30fc\u30c9\u3067\u306f\u5b9f\u884c\u7d50\u679c\u304c\u9055\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n        Dim a As New AClass\r\n        ' ToString \u306e\u5834\u5408\r\n        Debug.Print(a.ToString())\r\n        ' Cast \u306e\u5834\u5408\r\n        Debug.Print(CType(a, String))\r\n<\/pre>\n<p>\u25bc\u5b9f\u884c\u7d50\u679c<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nToString AClass\r\nCast AClass\r\n<\/pre>\n<p>\u3053\u3093\u306a\u98a8\u306b\u3001ToString \u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u6642\u306f\u3001\u601d\u3063\u305f\u3068\u304a\u308a\u306b\u306f\u52d5\u304b\u306a\u3044\u306e\u3067\u3059\u3002\u307e\u3041\u3001\u3053\u3046\u3044\u3046\u6642\u306f\u3001String \u578b\u3078\u306e\u30ad\u30e3\u30b9\u30c8\u81ea\u4f53\u3082\u5371\u3046\u3044\u3068\u3053\u308d\u306a\u306e\u3067\u3059\u304c\u3001\u3072\u3068\u307e\u305a ToString \u3068\u30ad\u30e3\u30b9\u30c8\u306f\u9055\u3046\u52d5\u4f5c\u3092\u3059\u308b\u3001\u3063\u3066\u3053\u3068\u3092\u899a\u3048\u3066\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u6b32\u3057\u3044\u306a\u3041\u3001\u3068\u3002<\/p>\n<p>\u4f59\u8ac7\u3092\u8a00\u3048\u3070\u3001\u30ad\u30e3\u30b9\u30c8\u306e\u5834\u5408\u306f string \u578b\u306b\u30ad\u30e3\u30b9\u30c8\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u4f8b\u5916\u3092\u767a\u751f\u3055\u305b\u308b\u3051\u3069\u3001ToString \u578b\u306f\u4f8b\u5916\u306b\u306f\u306a\u3089\u306a\u3044(\u591a\u5206\u306a\u3089\u306a\u3044)\u3067\u3059\u3088\u306d\u3002\u3053\u306e\u3042\u305f\u308a\u3001\u610f\u56f3\u3057\u3066 ToString \u30e1\u30bd\u30c3\u30c9(ToInteger\u30e1\u30bd\u30c3\u30c9\u3068\u304b\u3068\u540c\u5217\u306e\u610f\u5473\u3067)\u3092\u4f7f\u3046\u5206\u306b\u306f ok \u3063\u3066\u3053\u3068\u306a\u306e\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3044\u3064\u307e\u3067\u3082\u5371\u306a\u3044\uff08\uff1f\uff09PDF\u3092\u6652\u3057\u3066\u304a\u304f\u308f\u3051\u306b\u306f\u884c\u304b\u306a\u3044\u306e\u3067\uff57\u3001\u5c0f\u30cd\u30bf\u3067\u30d6\u30ed\u30b0\u3092\u9032\u3081\u307e\u3059\u3002 \u6642\u3005(\u7279\u306bVB\u30d7\u30ed\u30b0\u30e9\u30de\u306e\u65b9\uff1f)\u3067\u306f\u3001\u6587\u5b57\u5217\u3078\u306e\u30ad\u30e3\u30b9\u30c8\u3092 ToString \u3067\u884c\u3063\u3066\u3044\u308b\u7b87\u6240\u3092\u898b\u639b\u3051\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u5371\u3046\u3044\u3067 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2215\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2215","post","type-post","status-publish","format-standard","hentry","category-dev"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=2215"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2215\/revisions"}],"predecessor-version":[{"id":2216,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2215\/revisions\/2216"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=2215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=2215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=2215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}