{"id":34589,"date":"2023-04-07T15:49:26","date_gmt":"2023-04-07T10:19:26","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/"},"modified":"2023-04-07T15:49:26","modified_gmt":"2023-04-07T10:19:26","slug":"solved-how-do-i-use-the-c6-using-static-feature","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/","title":{"rendered":"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?"},"content":{"rendered":"<h2 id=\"Introduction\">Introduction<\/h2>\n<p>[ad_1]<\/p>\n<p>The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. This can be especially useful when dealing with large namespaces or when you want to avoid typing out long type names. In this article, we will discuss how to use the &#8220;Using static&#8221; feature in C#6 and provide some examples of how it can be used.<\/p>\n<h2 id=\"solution\"> Solution<\/h2>\n<p>The &#8220;Using static&#8221; feature in C#6 allows you to access static members of a type without having to specify the type name. To use this feature, you must first add a &#8220;using static&#8221; directive to the top of your code file, specifying the type whose static members you want to access. For example, if you wanted to access the static members of the System.Math type, you would add the following directive to the top of your code file:<\/p>\n<p>using static System.Math;<\/p>\n<p>Once you have added the directive, you can access the static members of the type without having to specify the type name. For example, you can call the Math.Sqrt() method without having to specify the type name:<\/p>\n<p>double result = Sqrt(4); <\/p>\n<p>[ad_2]<br \/>\n<\/p>\n<div id=\"answer-31852390\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"31852390\" data-parentid=\"31852389\" data-score=\"227\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>It appears the syntax has slightly changed since those blog posts were written. As the error message suggests, add <code>static<\/code> to your include statement:<\/p>\n<pre><code>using static System.Console;\n\/\/      ^\nclass Program \n{ \n    static void Main() \n    { \n        WriteLine(\"Hello world!\"); \n        WriteLine(\"Another message\"); \n    } \n}\n<\/code><\/pre>\n<p>Then, your code will compile.<\/p>\n<hr>\n<p>Note that, in C# 6.0, this will only work for members declared as <code>static<\/code>.<\/p>\n<p>For example, consider <code>System.Math<\/code>: <\/p>\n<pre><code>public static class Math {\n    public const double PI = 3.1415926535897931;\n    public static double Abs(double value);\n    \/\/ &lt;more stuff&gt;\n}\n<\/code><\/pre>\n<p>When <code>using static System.Math<\/code>, you can just use <code>Abs();<\/code>.<br \/>\nHowever, you&#8217;d still have to prefix <code>PI<\/code> because it isn&#8217;t a static member: <code>Math.PI;<\/code>.<\/p>\n<p>Starting with C# version 7.2, this shouldn&#8217;t be the case, <code>const<\/code> values like <code>PI<\/code> can be used as well.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">14<\/span> <\/p><\/div>\n<\/div>\n<div id=\"end\">  <\/div>\n<h1>How do I use the C#6 &#8220;Using static&#8221; Feature?<\/h1>\n<p>The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. This can be especially useful when dealing with large namespaces or when you want to avoid typing out long type names.<\/p>\n<h2>Steps to Use the C#6 &#8220;Using static&#8221; Feature<\/h2>\n<ol>\n<li>Create a new C# project in Visual Studio.<\/li>\n<li>Add a reference to the type you want to use the &#8220;Using static&#8221; feature with.<\/li>\n<li>Add the &#8220;using static&#8221; directive to the top of the file.<\/li>\n<li>Use the static members of the type without having to specify the type name.<\/li>\n<\/ol>\n<h2>Example<\/h2>\n<p>Let&#8217;s say you want to use the static members of the System.Math type. You can do this by adding the following line to the top of your file:<\/p>\n<pre><code>using static System.Math;<\/code><\/pre>\n<p>Now you can use the static members of the System.Math type without having to specify the type name. For example, you can use the Sqrt() method like this:<\/p>\n<pre><code>double result = Sqrt(4);<\/code><\/pre>\n<p>This is much simpler than having to type out the full type name each time you want to use a static member.<\/p>\n<h2>Conclusion<\/h2>\n<p>The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. Give it a try and see how it can help you write better code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction [ad_1] The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. This can be especially useful when dealing with large namespaces or when you want to avoid typing &#8230; <a title=\"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\" aria-label=\"More on [Solved] How do I use the C#6 &#8220;Using static&#8221; feature?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[6079,324,903,1714,1797],"class_list":["post-34589","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c-6-0","tag-c","tag-static","tag-using","tag-visual-studio-2015"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How do I use the C#6 &quot;Using static&quot; feature? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How do I use the C#6 &quot;Using static&quot; feature? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"Introduction [ad_1] The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. This can be especially useful when dealing with large namespaces or when you want to avoid typing ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-07T10:19:26+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?\",\"datePublished\":\"2023-04-07T10:19:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\"},\"wordCount\":554,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c#-6.0\",\"c++\",\"static\",\"using\",\"visual-studio-2015\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\",\"name\":\"[Solved] How do I use the C#6 \\\"Using static\\\" feature? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-04-07T10:19:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How do I use the C#6 \"Using static\" feature? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How do I use the C#6 \"Using static\" feature? - JassWeb","og_description":"Introduction [ad_1] The C#6 &#8220;Using static&#8221; feature is a great way to simplify your code and make it easier to read. It allows you to access static members of a type without having to specify the type name. This can be especially useful when dealing with large namespaces or when you want to avoid typing ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/","og_site_name":"JassWeb","article_published_time":"2023-04-07T10:19:26+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?","datePublished":"2023-04-07T10:19:26+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/"},"wordCount":554,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c#-6.0","c++","static","using","visual-studio-2015"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/","url":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/","name":"[Solved] How do I use the C#6 \"Using static\" feature? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-04-07T10:19:26+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-i-use-the-c6-using-static-feature\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How do I use the C#6 &#8220;Using static&#8221; feature?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/34589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=34589"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/34589\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=34589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=34589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=34589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}