From 277fca90408f0178bec0faaeb264760de61f7457 Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:54:20 -0400 Subject: [PATCH 1/9] Expanded on definition of a static class --- content/c-sharp/concepts/classes/classes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index 17a17adb7f8..c4fc938b993 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -89,7 +89,8 @@ public class BankAccount { ## Static Classes -Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. +Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. +The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. ## Partial classes From c17fb22518d57420a26a7c37a254d76d25e9050f Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:15:06 -0400 Subject: [PATCH 2/9] Example for static classes added --- content/c-sharp/concepts/classes/classes.md | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index c4fc938b993..7d48cb1e950 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -92,6 +92,39 @@ public class BankAccount { Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. +### Example +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can't do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create fields and methods in the class and how we use our static class in other classes. + +```cs +using System; + +public class Main +{ + public static void Main() + { + //The following will produce a compile time error + //MyStaticClass NonStaticError = new MyStaticClass(): + + // + int DoubleFive = MyStaticClass.GetDouble(5); + Console.WriteLine(DoubleFive); + } +} + +public static class MyStaticClass +{ + //The folowing will produce a compile time error + //public int NonStaticField = 5; + + public static int StaticField = 10; + + //Returns double of the value given + public static int GetDouble(int value) { + return value * 2; + } +} +``` + ## Partial classes Partial classes in C# enable class definitions to be split across multiple files. Each part of the class is defined in a separate file and combined at compile time to create a single class. This is valuable for scenarios where a class becomes too large or complex, or when multiple developers need to work on different aspects of the class simultaneously. From eaae2ec062d7b5c6b9d684173db53b4b52d5b010 Mon Sep 17 00:00:00 2001 From: russellzj <26415974+Russellzj@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:40:29 -0400 Subject: [PATCH 3/9] Change example description --- content/c-sharp/concepts/classes/classes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index 7d48cb1e950..cd4c5bdfc83 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -93,7 +93,11 @@ Static classes are defined using the `static` keyword and exclusively contain st The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. ### Example +<<<<<<< HEAD In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can't do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create fields and methods in the class and how we use our static class in other classes. +======= +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. +>>>>>>> ffb4726d (Example for static classes added) ```cs using System; From 7a0c3426b5f90d4572b453630dbc00aa6cc98ff1 Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:54:20 -0400 Subject: [PATCH 4/9] Expanded on definition of a static class --- content/c-sharp/concepts/classes/classes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index 17a17adb7f8..c4fc938b993 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -89,7 +89,8 @@ public class BankAccount { ## Static Classes -Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. +Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. +The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. ## Partial classes From 75020e0b43a8c1dce71f9ee57e3b50e963a32137 Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:15:06 -0400 Subject: [PATCH 5/9] Example for static classes added --- content/c-sharp/concepts/classes/classes.md | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index c4fc938b993..7d48cb1e950 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -92,6 +92,39 @@ public class BankAccount { Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. +### Example +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can't do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create fields and methods in the class and how we use our static class in other classes. + +```cs +using System; + +public class Main +{ + public static void Main() + { + //The following will produce a compile time error + //MyStaticClass NonStaticError = new MyStaticClass(): + + // + int DoubleFive = MyStaticClass.GetDouble(5); + Console.WriteLine(DoubleFive); + } +} + +public static class MyStaticClass +{ + //The folowing will produce a compile time error + //public int NonStaticField = 5; + + public static int StaticField = 10; + + //Returns double of the value given + public static int GetDouble(int value) { + return value * 2; + } +} +``` + ## Partial classes Partial classes in C# enable class definitions to be split across multiple files. Each part of the class is defined in a separate file and combined at compile time to create a single class. This is valuable for scenarios where a class becomes too large or complex, or when multiple developers need to work on different aspects of the class simultaneously. From bd32b5ee0678e41201c2ed3e5c8ea8b889173ec3 Mon Sep 17 00:00:00 2001 From: russellzj <26415974+Russellzj@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:40:29 -0400 Subject: [PATCH 6/9] Change example description --- content/c-sharp/concepts/classes/classes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index 7d48cb1e950..cd4c5bdfc83 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -93,7 +93,11 @@ Static classes are defined using the `static` keyword and exclusively contain st The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. ### Example +<<<<<<< HEAD In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can't do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create fields and methods in the class and how we use our static class in other classes. +======= +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. +>>>>>>> ffb4726d (Example for static classes added) ```cs using System; From bf152efbe82b55ed20b04527aa98a0180ccf18f7 Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:05:51 -0400 Subject: [PATCH 7/9] Made minor changes suggested from pull request --- content/c-sharp/concepts/classes/classes.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index cd4c5bdfc83..9cbcb8f418f 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -93,21 +93,18 @@ Static classes are defined using the `static` keyword and exclusively contain st The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. ### Example -<<<<<<< HEAD -In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can't do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create fields and methods in the class and how we use our static class in other classes. -======= + In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. ->>>>>>> ffb4726d (Example for static classes added) ```cs using System; -public class Main +public class Program { public static void Main() { - //The following will produce a compile time error - //MyStaticClass NonStaticError = new MyStaticClass(): + //The following will produce a compile-time error + //MyStaticClass NonStaticError = new MyStaticClass(); // int DoubleFive = MyStaticClass.GetDouble(5); @@ -117,7 +114,7 @@ public class Main public static class MyStaticClass { - //The folowing will produce a compile time error + //The following will produce a compile-time error //public int NonStaticField = 5; public static int StaticField = 10; From 0f0ccfbf65ac1e182c28123554e21fa6c845232f Mon Sep 17 00:00:00 2001 From: Zachariah Russell <26415974+Russellzj@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:52:10 -0400 Subject: [PATCH 8/9] Removed misc whitespaces and replace tabs with spacing --- content/c-sharp/concepts/classes/classes.md | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index 9cbcb8f418f..f6a388f6961 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -92,37 +92,36 @@ public class BankAccount { Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. -### Example +## Example -In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. ```cs using System; - + public class Program { - public static void Main() - { - //The following will produce a compile-time error - //MyStaticClass NonStaticError = new MyStaticClass(); + public static void Main() + { + //The following will produce a compile-time error + //MyStaticClass NonStaticError = new MyStaticClass(); - // - int DoubleFive = MyStaticClass.GetDouble(5); - Console.WriteLine(DoubleFive); - } + int DoubleFive = MyStaticClass.GetDouble(5); + Console.WriteLine(DoubleFive); + } } public static class MyStaticClass { - //The following will produce a compile-time error - //public int NonStaticField = 5; - - public static int StaticField = 10; - + //The following will produce a compile-time error + //public int NonStaticField = 5; + + public static int StaticField = 10; + //Returns double of the value given - public static int GetDouble(int value) { - return value * 2; - } + public static int GetDouble(int value) { + return value * 2; + } } ``` From a270ac5e14f767dbfa7e5e7c97ca854353253780 Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Thu, 21 Nov 2024 11:38:52 +0530 Subject: [PATCH 9/9] Minor changes --- content/c-sharp/concepts/classes/classes.md | 50 ++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/content/c-sharp/concepts/classes/classes.md b/content/c-sharp/concepts/classes/classes.md index f6a388f6961..053ff4cf9e2 100644 --- a/content/c-sharp/concepts/classes/classes.md +++ b/content/c-sharp/concepts/classes/classes.md @@ -89,42 +89,52 @@ public class BankAccount { ## Static Classes -Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionality. -The `static` keyword forces all fields, methods and properties to require the static keyword. This means that if you try to create any of these without the static keyword the code will not run and will produce a compile-time error. The reason behind this is that becuase you can not create an instance of a static class any methods, properties and fields that are not marked as static would be unreachable. +Static classes are defined using the `static` keyword and exclusively contain static members, such as methods, properties, and fields. Unlike regular classes, static classes cannot be instantiated with the `new` keyword. Instead, their members are accessed using the class name itself. These classes are commonly used for utility functions or to group related functionalities. -## Example +The `static` keyword forces all fields, methods, and properties to require this keyword. This means that if a user tries to create any of these without the `static` keyword, the code will not run and will produce a compile-time error. The reason behind this is that the user can not create an instance of a static class without using this keyword. Any methods, properties and fields that are not marked as `static` would be unreachable. -In the example below, a static class called `MyStaticClass` is created. The commented out code shows what you can not do with static classes. If these commented out pieces of code were to be uncommented the code would not compile. Take note on how we create properties and methods in the class and how we use it in the `CallingClass` class. +### Example + +In the example below, a static class called `MyStaticClass` is created. The commented out code shows what a user can not do with static classes. If these commented out pieces of code were to be uncommented, the code would not compile. The example also shows how properties and methods in the `MyStaticClass` class are created and used in the `CallingClass` class: ```cs using System; - -public class Program + +public class CallingClass { - public static void Main() - { - //The following will produce a compile-time error - //MyStaticClass NonStaticError = new MyStaticClass(); - - int DoubleFive = MyStaticClass.GetDouble(5); - Console.WriteLine(DoubleFive); - } + public static void Main() + { + Console.WriteLine(MyStaticClass.StaticField); + + // The following will produce a compile-time error + // MyStaticClass NonStaticError = new MyStaticClass(); + + int DoubleFive = MyStaticClass.GetDouble(5); + Console.WriteLine(DoubleFive); + } } public static class MyStaticClass { - //The following will produce a compile-time error - //public int NonStaticField = 5; + // The following will produce a compile-time error + // public int NonStaticField = 5; - public static int StaticField = 10; + public static int StaticField = 20; - //Returns double of the value given - public static int GetDouble(int value) { + // Returns double of the value given + public static int GetDouble(int value) { return value * 2; - } + } } ``` +The above code produces the following output: + +```shell +20 +10 +``` + ## Partial classes Partial classes in C# enable class definitions to be split across multiple files. Each part of the class is defined in a separate file and combined at compile time to create a single class. This is valuable for scenarios where a class becomes too large or complex, or when multiple developers need to work on different aspects of the class simultaneously.