This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| // Define an abstract class called 'Shape' | |
| abstract class Shape { | |
| // An abstract method for calculating area, to be implemented by derived classes. | |
| public abstract double CalculateArea(); | |
| // A non-abstract method with a default implementation. | |
| public void DisplayArea() { | |
| Console.WriteLine('Area: ' + CalculateArea()); } | |
| } | |
| // Create a derived class 'Circle' that inherits from 'Shape' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Restaurants : IEnumerable | |
| { | |
| readonly public List<Restaurant> restaurants = new List<Restaurant> | |
| { | |
| new Restaurant("Pizza", true), | |
| new Restaurant("Hamburger", false), | |
| new Restaurant("Bread", true) | |
| }; | |
| public GetEnumerator() => new OpenRestaurantsEnumerator(restaurants); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OpenRestaurantsEnumerator : IEnumerator | |
| { | |
| private readonly List<Restaurant> _restaurants; | |
| private int _position = -1; | |
| public OpenRestaurantsEnumerator(List<Restaurant> restaurants) | |
| { | |
| _restaurants = restaurants; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Restaurants : IEnumerable | |
| { | |
| readonly public List<Restaurant> restaurants = new List<Restaurant> | |
| { | |
| new Restaurant("Pizza", true), | |
| new Restaurant("Hamburger", false), | |
| new Restaurant("Bread", true) | |
| }; | |
| public IEnumerator GetEnumerator() => restaurants.GetEnumerator(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Without inheritance | |
| public class SavingsAccount | |
| { | |
| private double balance; | |
| public double GetBalance() | |
| { | |
| return this.balance; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace virgol | |
| { | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| UserMsg.sayGoodMorning(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main() | |
| { | |
| MathHelperNonStatic mathHelper = new MathHelperNonStatic(); | |
| int result = mathHelper.Add(1, 2); | |
| Console.WriteLine(result); | |
| } | |
| public class MathHelperNonStatic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main() | |
| { | |
| MathHelperExe(); | |
| } | |
| public static class MathHelper | |
| { | |
| public static int Add(int a, int b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for(int i = 0; i < 50; i++) | |
| { | |
| if(i % 7 == 0) | |
| { | |
| Console.WriteLine(i); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Console.WriteLine("soheil \t moonesi"); | |
| soheil moonesi | |
| Console.WriteLine("soheil \n moonesi"); | |
| soheil | |
| moonesi | |
| Console.WriteLine("soheil \v moonesi"); | |
| soheil | |
| moonesi |
NewerOlder