Tutorialspoint

Mono Program Empty Template

using System.IO;
using System;
using System.Net.Mail;
using System.Net;
using System.Configuration;

class Program
{
    static void Main()
    {
        #region AWS email send 
                 try
                {
                    // Replace sender@example.com with your "From" address. 
                    // This address must be verified with Amazon SES.
                   
                }
                catch (Exception ex)
                {

                    throw;
                }
                #endregion
    }
}

dhinesh

using System.IO;
using System;

					
public class Program
{
	public static void Main()
	{

		Console.WriteLine(ExcelColumnFromNumber(27));
	}
	public static string ExcelColumnFromNumber(int column)
    {
        string columnString = "";
        decimal columnNumber = column;
        while (columnNumber > 0)
        {
            decimal currentLetterNumber = (columnNumber - 1) % 26;
            char currentLetter = (char)(currentLetterNumber + 65);
            columnString = currentLetter + columnString;
            columnNumber = (columnNumber - (currentLetterNumber + 1)) / 26;
        }
        return columnString;
    }
}

C# Basic Syntax

using System;

namespace RectangleApplication {
   
   class Rectangle {
      public void Acceptdetails() {
          double length = 4.5;    
         double width = 3.5;
      }
      
      public double GetArea() {
         return length * width; 
      }
      
      public void Display() {
         Console.WriteLine("Length: {0}", length);
         Console.WriteLine("Width: {0}", width);
         Console.WriteLine("Area: {0}", GetArea());
      }
   }
   
   class ExecuteRectangle {
   
      static void Main(string[] args) {
         Rectangle r = new Rectangle();
         r.Acceptdetails();
         r.Display();
         Console.ReadLine(); 
      }
   }
}

Compile and Execute C# Sharp Online

using UnityEngine;

/// 
/// Контроллер и поведение игрока
/// 
public class PlayerScript : MonoBehaviour
{
  /// 
  /// 1 - скорость движения
  /// 
  public Vector2 speed = new Vector2(50, 50);

  // 2 - направление движения
  private Vector2 movement;

  void Update()
  {
    // 3 -  извлечь информацию оси
    float inputX = Input.GetAxis("Horizontal");
    float inputY = Input.GetAxis("Vertical");

    // 4 - движение в каждом направлении
    movement = new Vector2(
      speed.x * inputX,
      speed.y * inputY);

  }
}

C# - Hashtable Class

using System;
using System.Collections;

public class ExampleHashtable
{
    public void exampleAdd()
    {
        Hashtable Ht = new Hashtable();

        Ht.Add(01, "This");
        Ht.Add(03, "is");
        Ht.Add(04, "my");
        Ht.Add(06, "system");
        int i = 0;
        foreach(var h in Ht)
        {
            Console.WriteLine("Ht["+ i + "] = " +Ht[i++]); 
        }
        ICollection ic;
        ic = Ht.Keys;
        foreach(var k in ic)
        {
            Console.WriteLine(k);
        }
        if (Ht.ContainsKey(04))
        {
            Console.WriteLine("Key found");
        }
        else
        {
            Console.WriteLine("Key not found");
        }
        if (Ht.ContainsValue("my"))
        {
            Console.WriteLine("value found");

        }
        else
        {
            Console.WriteLine("value not found");
        }
    }
}


namespace collectionHashtable
{
    class Program
    {
        static void Main(string[] args)
        {
            ExampleHashtable ht = new ExampleHashtable();
            ht.exampleAdd();
            Console.WriteLine("It Works");
         }
    }
}

sin(math.pi)

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine(Math.Sin(Math.PI));
    }
}

Compile and Execute C# Sharp Online

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApp3
{
    namespace kartoteka
    {
        public class Osoba
        {
            private string imie;
            private string nazwisko;
            public Osoba() { }
            public Osoba(string _imie, string _nazwisko)
            {
                this.imie = _imie;
                this.nazwisko = _nazwisko;
            }

            public string getImie()
            {
                return this.imie;
            }
            public string getNazwisko()
            {
                return this.nazwisko;
            }
        }
        namespace mockup
        {
            public class Kartoteka
            {                
                public static void dodaj(kartoteka.Osoba osoba){ }
                public static void usun(kartoteka.Osoba osoba) { }
                public static int rozmiar() { return 1; }
                public static bool czyZawiera() { return true; }
                public static Osoba pobierz() { return new Osoba("Gall", "Anonim"); }
            }
        }
        namespace impl
        {
            public class Kartoteka
            {              
                public static List<Osoba> kartoteka = new List<Osoba>();
                
                public static void wypisz()
                {
                    foreach(Osoba x in kartoteka)
                    {
                        Console.WriteLine(x.getImie() +" "+x.getNazwisko());
                    }                        
                }
                public static void dodaj(Osoba osoba) { kartoteka.Add(osoba); } 
                public static void usun(Osoba osoba)  { kartoteka.Remove(osoba); }
                public static int rozmiar() {
                    Console.WriteLine(kartoteka.Count);
                    return kartoteka.Count; }
                public static bool czyZawiera(Osoba osoba)
                {
                    if (kartoteka.Contains(osoba))
                    {
                        Console.WriteLine("BRAK OSOBY");
                        return true;
                    }
                    else
                    {
                        Console.WriteLine("BRAK OSOBY");
                        return false;
                    }
                }
                public static Osoba pobierz(int i)
                {
                    var czlowiek = kartoteka[i];
                    Console.WriteLine(czlowiek.getImie() + " " + czlowiek.getNazwisko());
                    return czlowiek;
                }
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int caseSwitch = 9;
            string imie;
            string nazwisko;
            Console.WriteLine("1. DODAJ.");
            Console.WriteLine("2. USUN.");
            Console.WriteLine("3. WYPISZ.");
            Console.WriteLine("4. CZY ZAWIERA.");
            Console.WriteLine("5. POBIERZ INDEKS.");
            Console.WriteLine("6. ROZMIAR. \n");
            
            while (caseSwitch!=0)
            {
                caseSwitch = Convert.ToInt32(Console.ReadLine());
                switch (caseSwitch)
                {
                    case 1:
                        Console.WriteLine("PODAJ IMIE:");
                        imie = Console.ReadLine();
                        Console.WriteLine("PODAJ NAZWISKO");
                        nazwisko = Console.ReadLine();
                        kartoteka.impl.Kartoteka.dodaj(new kartoteka.Osoba(imie,nazwisko));
                        break;
                    case 2:
                        kartoteka.impl.Kartoteka.wypisz();
                        Console.WriteLine("PODAJ NAZWISKO:");
                        string naz;
                        naz = Console.ReadLine();
                        var ludzik = kartoteka.impl.Kartoteka.kartoteka.Find(x => x.getNazwisko().Equals(naz));
                        
                        kartoteka.impl.Kartoteka.usun(ludzik);
                        break;
                    case 3:
                        kartoteka.impl.Kartoteka.wypisz();
                        break;
                    case 4:
                        string naz2;
                        Console.WriteLine("PODAJ NAZWISKO:");
                        naz2 = Console.ReadLine();
                        var ludzik2 = kartoteka.impl.Kartoteka.kartoteka.Find(x => x.getNazwisko().Equals(naz2));
                        kartoteka.impl.Kartoteka.czyZawiera(ludzik2);
                        break;
                    case 5:
                        Console.WriteLine("PODAJ NUMER INDEKSU:");
                        int numer;
                        numer = Convert.ToInt32(Console.ReadLine());
                        kartoteka.impl.Kartoteka.pobierz(numer);
                        break;
                    case 6:
                        kartoteka.impl.Kartoteka.rozmiar();
                        break;                        
                }
            }
        }
    }
}

Compile and Execute C# Sharp Online

using System;
namespace Rextester
{
class Test
{
     public  void LevelLoad(int[] ar)
    {
      int n=ar.Length;
      Random rand= new Random();
      for(int i=0;i<n;i++)
      {
          Swap(ar,i,i+rand.Next(n-i));
      }
    }
 public void Swap(int[] ar,int a,int b)
    {
     int temp=ar[a];
     ar[a]=ar[b];
     ar[b]=temp;
    } 
}
class Program
{
static void Main(string[] args)
{
     
   int[] arr= new int[] { 1, 2, 3 ,4,5,6,7,8};
    Test t=new Test();
    t.LevelLoad(arr);
    Console.WriteLine("..................................");
    for(int j=0;j<arr.Length;j++)
      {
          Console.WriteLine(arr[j]);
      }

    //...............................
   
}
}
}

programming assignment vp542019

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Programming Assignment, Viktori Patalainen");
        Problem1();
        Problem3();
    }
    
    static void Problem1() 
    {
        int a = 3;
        int b = 5;
        int c = a * b;
        int result = 0;
        
        for (int i = 199; i > 0; i--) 
        {
            result += b * i;
        }
        
        for (int j = 333; j > 0; j--) 
        {
            result += a * j;
        }
        
        int subs = 0;
        
        for (int k = 66; k > 0; k--) 
        {
            subs += k * c;
        }
        
        int sum = result - subs;
        
        Console.WriteLine(sum);
    }
    
    static void Problem3() 
    {
        int[] test = {1,3,5,7,9,12,2,4,6,8};
        
        int sum = ArrayPairSum(test);
        
        Console.WriteLine(sum);
    }
    
    static int ArrayPairSum(int[] nums) 
    {
        Array.Sort(nums);
        
        int sum = 0;
        
        for (int i = 0; i < nums.Length; i+=2) 
        {
            sum += Math.Min(nums[i], nums[i+1]);
        }
        
        return sum;
    }
    
}

RandomPatterForPerlinNoise

using System.IO;
using System;

class Program
{
    static void Main()
    {
        //Random random = new Random();
        //int rnd = random.Next(256);
        //Console.WriteLine("random: " + rnd);
        
        RandomPatter rp = new RandomPatter();
        rp.generateShufflePatter();
        rp.printPatter(16, 16);
    }
}

class RandomPatter
{
    private int m_size;
    private int[] m_sortedPatter;
    private int[] m_randomPatter;
    
    public RandomPatter()
    {
        m_size = 256;
        m_sortedPatter = new int[m_size];
        m_randomPatter = new int[m_size];
    }
    
    
    private int[] generateSortedPatter()
    {
        for(int i=0; i<m_size; i++)
        {
            m_sortedPatter[i] = i;
        }
        
        return m_sortedPatter;
    }
    
    
    public int[] generateShufflePatter()
    {
        m_sortedPatter = generateSortedPatter();
        
        for(int i=0; i<m_size; i++)
        {
            m_randomPatter[i] = m_sortedPatter[i];
        }

        for(int i=0; i<100; i++)
        {
            //int rand1 = Random.Range(0, 256);
            //int rand2 = Random.Range(0, 256);
            Random rand = new Random();
            int rand1 = (int)(rand.NextDouble() * 256);
            int rand2 = (int)(rand.NextDouble() * 256);

            int toggle = m_randomPatter[rand1];
            m_randomPatter[rand1] = m_randomPatter[rand2];
            m_randomPatter[rand2] = toggle;
        }
        
        return m_randomPatter;
    }
    

    public void printPatter(int w, int h)
    {
        int i = 0;
        for(int y=0; y<h; y++)
        {
            for(int x=0; x<w; x++)
            {
                if(m_randomPatter[i] < 10)
                {
                    Console.Write("  ");
                }
                else if(m_randomPatter[i] < 100)
                {
                    Console.Write(" ");
                }
                
                Console.Write(m_randomPatter[i++]);
                Console.Write(" ");
            }
            
            Console.WriteLine("");
            
        }
    }
    
    
    
    
}

1 2 3 4 5 6 7 ... 257 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.