-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Edit] C# Classes: Static Definition #5460 #5462
base: main
Are you sure you want to change the base?
Conversation
962b4f8
to
bd32b5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Russellzj ,
LGTM! This entry looks good for Second round of review.
Thanks,
Savi
### 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. | ||
======= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
======= |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>>>>>> ffb4726d (Example for static classes added) |
Remove this line.
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} | |
} | |
using System; | |
public class Program | |
{ | |
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 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; | |
} | |
} |
@Russellzj please commit the changes made by @SaviDahegaonkar before we can move to second review. |
Just committed the changes that were requested! |
Description
Added an expanded description of C# static class. Also, included examples for using and creating static classes.
Issue Solved
Issue: [Edit] C# Classes #5429
Type of Change
Checklist
main
branch.Issues Solved
section.