{"id":25438,"date":"2024-07-27T08:13:53","date_gmt":"2024-07-26T23:13:53","guid":{"rendered":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25438"},"modified":"2024-07-27T08:13:55","modified_gmt":"2024-07-26T23:13:55","slug":"c%e3%81%ae%e5%9f%ba%e7%a4%8e","status":"publish","type":"post","link":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25438","title":{"rendered":"C#\u306e\u57fa\u790e"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>C#\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u57fa\u672c\u7684\u306a\u69cb\u9020\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nusing System;\n\nnamespace HelloWorld\n{\n    class Program\n    {\n        static void Main(string&#91;] args)\n        {\n            Console.WriteLine(\"Hello, World!\");\n        }\n    }\n}\n\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\"Hello, World!\"\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3057\u307e\u3059\u3002\n\n2. \u5909\u6570\u3068\u30c7\u30fc\u30bf\u578b\nC#\u306b\u306f\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u578b\u304c\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u578b\u3068\u5909\u6570\u306e\u5ba3\u8a00\u65b9\u6cd5\u3067\u3059\uff1a\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nint integerNumber = 10;\ndouble doubleNumber = 20.5;\nchar singleCharacter = 'A';\nstring text = \"Hello, C#\";\nbool isTrue = true;\n3. \u6f14\u7b97\u5b50\nC#\u3067\u306f\u3001\u57fa\u672c\u7684\u306a\u7b97\u8853\u6f14\u7b97\u5b50\u3001\u6bd4\u8f03\u6f14\u7b97\u5b50\u3001\u8ad6\u7406\u6f14\u7b97\u5b50\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nint a = 10;\nint b = 20;\n\nint sum = a + b; \/\/ \u52a0\u7b97\nint diff = a - b; \/\/ \u6e1b\u7b97\nint product = a * b; \/\/ \u4e57\u7b97\nint quotient = a \/ b; \/\/ \u9664\u7b97\nint remainder = a % b; \/\/ \u5270\u4f59\n\nbool isEqual = (a == b); \/\/ \u7b49\u3057\u3044\u304b\u3069\u3046\u304b\nbool isGreater = (a > b); \/\/ \u5927\u304d\u3044\u304b\u3069\u3046\u304b\nbool isLess = (a &lt; b); \/\/ \u5c0f\u3055\u3044\u304b\u3069\u3046\u304b\n\nbool andCondition = (a > 5 &amp;&amp; b &lt; 30); \/\/ AND\nbool orCondition = (a > 15 || b &lt; 25); \/\/ OR\nbool notCondition = !(a == b); \/\/ NOT\n4. \u6761\u4ef6\u5206\u5c90\nC#\u3067\u306f\u3001if\u6587\u3084switch\u6587\u3092\u4f7f\u3063\u3066\u6761\u4ef6\u5206\u5c90\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nint number = 10;\n\nif (number > 0)\n{\n    Console.WriteLine(\"Positive number\");\n}\nelse if (number &lt; 0)\n{\n    Console.WriteLine(\"Negative number\");\n}\nelse\n{\n    Console.WriteLine(\"Zero\");\n}\n\nswitch (number)\n{\n    case 0:\n        Console.WriteLine(\"Zero\");\n        break;\n    case 10:\n        Console.WriteLine(\"Ten\");\n        break;\n    default:\n        Console.WriteLine(\"Other number\");\n        break;\n}\n5. \u30eb\u30fc\u30d7\nC#\u3067\u306f\u3001for\u30eb\u30fc\u30d7\u3001while\u30eb\u30fc\u30d7\u3001do-while\u30eb\u30fc\u30d7\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\n\/\/ for\u30eb\u30fc\u30d7\nfor (int i = 0; i &lt; 5; i++)\n{\n    Console.WriteLine(i);\n}\n\n\/\/ while\u30eb\u30fc\u30d7\nint j = 0;\nwhile (j &lt; 5)\n{\n    Console.WriteLine(j);\n    j++;\n}\n\n\/\/ do-while\u30eb\u30fc\u30d7\nint k = 0;\ndo\n{\n    Console.WriteLine(k);\n    k++;\n} while (k &lt; 5);\n6. \u30e1\u30bd\u30c3\u30c9\nC#\u3067\u306f\u3001\u30b3\u30fc\u30c9\u3092\u518d\u5229\u7528\u53ef\u80fd\u306a\u5358\u4f4d\u306b\u5206\u3051\u308b\u305f\u3081\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        GreetUser(\"John\");\n    }\n\n    static void GreetUser(string name)\n    {\n        Console.WriteLine(\"Hello, \" + name);\n    }\n}\n7. \u30af\u30e9\u30b9\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\nC#\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e\u3067\u3042\u308a\u3001\u30af\u30e9\u30b9\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6982\u5ff5\u304c\u91cd\u8981\u3067\u3059\u3002\n\ncsharp\n\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3059\u308b\nclass Person\n{\n    public string Name { get; set; }\n    public int Age { get; set; }\n\n    public void Introduce()\n    {\n        Console.WriteLine(\"Hello, my name is \" + Name + \" and I am \" + Age + \" years old.\");\n    }\n}\n\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        Person person = new Person();\n        person.Name = \"Alice\";\n        person.Age = 30;\n        person.Introduce();\n    }\n}\n\u3053\u308c\u304cC#\u306e\u57fa\u790e\u7684\u306a\u6982\u5ff5\u3068\u69cb\u6587\u306e\u6982\u8981\u3067\u3059\u3002\u3055\u3089\u306b\u5b66\u3073\u305f\u3044\u5834\u5408\u306f\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3084\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[33],"tags":[35,3],"class_list":["post-25438","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25438"}],"version-history":[{"count":2,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25438\/revisions"}],"predecessor-version":[{"id":25440,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25438\/revisions\/25440"}],"wp:attachment":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25438"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}