Skip to content

Instantly share code, notes, and snippets.

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'
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);
class OpenRestaurantsEnumerator : IEnumerator
{
private readonly List<Restaurant> _restaurants;
private int _position = -1;
public OpenRestaurantsEnumerator(List<Restaurant> restaurants)
{
_restaurants = restaurants;
}
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();
// Without inheritance
public class SavingsAccount
{
private double balance;
public double GetBalance()
{
return this.balance;
}
}
namespace virgol
{
class Program
{
static void Main()
{
UserMsg.sayGoodMorning();
}
}
}
class Program
{
static void Main()
{
MathHelperNonStatic mathHelper = new MathHelperNonStatic();
int result = mathHelper.Add(1, 2);
Console.WriteLine(result);
}
public class MathHelperNonStatic
class Program
{
static void Main()
{
MathHelperExe();
}
public static class MathHelper
{
public static int Add(int a, int b)
for(int i = 0; i < 50; i++)
{
if(i % 7 == 0)
{
Console.WriteLine(i);
}
}
Console.WriteLine("soheil \t moonesi");
soheil moonesi
Console.WriteLine("soheil \n moonesi");
soheil
moonesi
Console.WriteLine("soheil \v moonesi");
soheil
moonesi