using System;
namespace C_Sharp_Console
{
///
/// My Very First C# Program.
///
///
using System;
using System.Collections; // needed for ArrayList
using System.IO ; // needed for file IO
public class Class1
{
///
/// This is a sample program that demonstrates
///
///- Output formatting
///- File I/O
///- ArrayLists
///- Iteration
///- Variable parameter lists
///- Random Number Generation
///- inline documentation
///
///
static void Main()
{
Class1 c = new Class1();
int x = 1 ;
int y = -2 ;
int z = 4 ;
int m = c.sum(3,1,4,1,5,9) ;
int n = c.sum(x,y,z) ;
Console.WriteLine("m={0}, n={1}",m,n) ;
ArrayList name = new ArrayList();
name.Add("Gizmo");
name.Add(75);
for(int i=0; i0)
{
Console.WriteLine("n={0}",n) ;
n-- ;
}
do
{
Console.WriteLine("n={0}",n) ;
n++ ;
} while(n<5) ;
StreamWriter outstr = new StreamWriter("testout.txt") ;
outstr.WriteLine("All your base are belong to us.") ;
outstr.Close() ;
StreamReader instr = new StreamReader("testout.txt") ;
string s = instr.ReadToEnd() ;
Console.WriteLine("File says: {0}", s) ;
Console.WriteLine("Random Number Generation:") ;
Random RNG = new Random() ;
for(int i=0; i<10; i++)
{
// Generate random ints in [10,99]:
int k = RNG.Next(10,100) ;
Console.WriteLine("k={0}",k) ;
}
}
public int sum(params int[] vals)
{
///
/// any number of integer arguments may be supplied
/// to this routine.
///
int temp=0 ;
foreach(int n in vals)
temp += n ;
return temp ;
}
}
}