Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C# Sharp Online

using System.IO;
using System;

namespace Program {
    

class Program
{
    static void Main()
    {
        
        Console.WriteLine("Hello, World!");
    
        
    }
}

}

C# - File I/O

using System;

namespace ReadCSVFileApplication {
   
   class ReadCSVFile {
	   
		 static void Main(string[] args) {
        {

            try
            {
				List<String> column1 = new ArrayList<String>();
                List<String> column2 = new ArrayList<String>();
				//Add remaining columns if exist
				StreamReader objReader = new StreamReader(@"received.csv");
				String row = objReader.ReadLine();
					if (!string.IsNullOrEmpty(row))
					{
 
						//Execute a loop over the columns.
						String[] arralistOfColumns= row.Split("##");
							column1.add(arralistOfColumns[0]);
							column2.add(arralistOfColumns[1]);
							//Asaign remaining columns if exist
					}

                String inputFile = @"C:\Users\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm";
                Excel.Application oXL = new Excel.Application();

                //Open a Excel File
                Excel.Workbook oWB = oXL.Workbooks.Add(inputFile);
                Excel._Worksheet oSheet = oWB.ActiveSheet;
              

                oSheet.Cells[1, 1] = "FirstColumn Name";
                oSheet.Cells[1, 2] = "SecondColumn Name"; // Here 1 is the rowIndex and 2 is the columnIndex.

                //Enter the Header data in Column A
                int i = 0;
                for (i = 0; i < Name.Count; i++)
                {
                    oSheet.Cells[i + 2, 1] = Name[i];
                }

                //Enter the Percentage data in Column B
                for (i = 0; i < Percentage.Count; i++)
                {
                    oSheet.Cells[i + 2, 2] = Percentage[i];
                }

               
                //String ReportFile = @"D:\Excel\Output.xls";
                oWB.SaveAs(inputFile, Excel.XlFileFormat.xlOpenXMLWorkbookMacroEnabled,
                                        Type.Missing, Type.Missing,
                                        false,
                                        false,
                                        Excel.XlSaveAsAccessMode.xlNoChange,
                                        Type.Missing,
                                        Type.Missing,
                                        Type.Missing,
                                        Type.Missing,
                                        Type.Missing);


                oXL.Quit();

                Marshal.ReleaseComObject(oSheet);
                Marshal.ReleaseComObject(oWB);
                Marshal.ReleaseComObject(oXL);

                oSheet = null;
                oWB = null;
                oXL = null;
                GC.GetTotalMemory(false);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.GetTotalMemory(true);
            }
            catch (Exception ex)
            {
				String errorMessage = "Error reading the Excel file : " + ex.Message;
			}

        }
   }
}

C# Program Structure

using System;

namespace HelloWorldApplication {
   
   class HelloWorld {
      
      static void Main(string[] args) {
         /* my first program in C# */
         Console.WriteLine("Hello World");
         Console.ReadKey();
      }
   }
}

Dynamics

using System.IO;
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dynamics
{
    class Program
    {
        static void Main(string[] args)
        {
            object obj = "foo";
            // obj.GetHashCode();
            
            // using reflection
            MethodInfo methodInfo = obj.GetType().GetMethod("GetHashCode");
            methodInfo.Invoke(null, null);
            
            // with reflection
            // object excelObject = "SomeExcelObject";
            // excelObject.Optimize();
            
            // using dynamic
            // dynamic excelObject = "SomeExcelObject";
            // excelObject.Optimize();
            
            //dynamic name = "Foo";
            //name++;
            
            dynamic x = 10;
            dynamic y = 20;
            var z = x + y;
            
            int a = 5;
            dynamic b = a;
            
            long l = b;
            
        }
    }
}

Combat Health Calculator

using System;

namespace HealthCalculator {

class Damage {
// member variables
double B;
// B = Blunt Damage being dealt to the entity.
double S;
// S = Sharp Damage being dealt to the entity.
double BT;
// BT = Blunt Damage Threshold of the entity.
double ST;
// ST = Sharp Damage Threshold of the entity.
double DR;
// DR = Damage Resistance % of the entity. Calculated by subtracting the DR Stat from 100 then divide by 100. 
double Limb;
// The Limb Damage multiplier for the entity. 
double Health;
// The total health of the entity. 

public void Acceptdetails() {
B = 40; 
S = 30;
BT = 10;
ST = 30;
DR = 5;
Limb = .8;
Health = 156.25;

}

public double GetHealth() {
return Health - ((((B - BT) + (S - ST) ) * (100 - DR) / 100) * Limb); 
}

public void Display() {
Console.WriteLine("Health: {0}", GetHealth());


}
}

class ExecuteRectangle {

static void Main(string[] args) {
Damage D = new Damage();
D.Acceptdetails();
D.Display();
Console.ReadLine(); 
}
}
}

Passing by Value and by Reference

using System.IO;
using System;

class Program
{
    int a = 10;
    int b = 20;
    string str1 = "before";
    string str2 = "after";
    
    private void DisplayNumbers(string txt, int int1, int int2)
    {
        Console.WriteLine("Numbers {0} swap : a = {1}, b = {2} ", txt, int1, int2);
    }
    
    private void SwapByValue(int int1, int int2)
    {
        Console.WriteLine("SwapbyValue is called.");
        int temp = int1;
        int1 = int2;
        int2 = temp;
    }
    
    private void SwapByRef(ref int int1, ref int int2)
    {
        Console.WriteLine("SwapbyRef is called.");
        int temp = int1;
        int1 = int2;
        int2 = temp;
    }
    
    static void Main()
    {
        Program p = new Program();
        
        p.DisplayNumbers(p.str1, p.a, p.b);
        p.SwapByValue(p.a,p.b);
        p.DisplayNumbers(p.str2, p.a, p.b);
        Console.WriteLine();
        
        p.DisplayNumbers(p.str1, p.a, p.b);
        p.SwapByRef(ref p.a,ref p.b);
        p.DisplayNumbers(p.str2, p.a, p.b);
    }
}

QQQQQQq3

using System;

namespace Question3_Q
{
   class ChackUp
    {
        public string txt1;
        public ChackUp(string str,string strP)
        {
            txt1 = str;
           Console.WriteLine( ChackPassWord(strP));
        }
        public string ChackPassWord(string strP)
        {
            string PP = "12345";
            if (PP == strP)
            {
                return txt1;
            }
            else return null;
        }
    }

Compile and Execute C# Sharp Online

using System.IO;
using System;

class Program
{
    static void Main()
    {
        int year,count,i,nofyear,j;
        year=7;
        nofyear=20;count=0;j=2;
        for(i=0;i<j;i++)
        {
            if(count<nofyear)
            {
                if(year%4==0||year%400==0)
                {
                    Console.WriteLine("{0}",year);
                    count++;
                }
                year++;
            }
        j++;
        }
    }
        
}

Compile and Execute C# Sharp Online

using System.IO;
using System;

class Program
{
    static void Main()
    {
        int a,i,b,c;
        a=4;b=0;c=0;
        for(i=0;i<a;i++)
        {
            b++;
            c=c+b;
        }
        Console.Write("sum of numbers={0}",c);
    }
}

Compile and Execute C# Sharp Online

using System.IO;
using System;

class Program
{
    static void Main()
    {
        int a,b;
        a=3;b=6;
    if(a<b)
    {
        Console.Write("{0}",b);
    }
    else
    {
        Console.Write("{0}",a);
    }
    }
}

Previous 1 ... 4 5 6 7 8 9 10 ... 257 Next
Advertisements
Loading...

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