// BASIC
static void Main(string[] args)
{
string name2 = "Zoloo";
string name3 = null;
string randStr = "Here are some random character";
Console.WriteLine("Whats your name:");
string name = Console.ReadLine();
Console.WriteLine("Hello " + name);
var aname = "Tom";
Console.WriteLine("var is: {0}", aname.GetTypeCode());
Console.ReadKey();
if (aname.GetTypeCode().ToString() == "String")
goto Cute;
Cute: Console.WriteLine("Hehe");
do
{
Console.WriteLine("Enter number:");
name = Console.ReadLine();
}
while (!name.Equals("15"));
foreach (char c in randStr)
{
Console.Write(c + " ");
}
Console.WriteLine("is empty " + String.IsNullOrEmpty(name3));
Console.WriteLine("is empty " + String.IsNullOrWhiteSpace(name2));
StringBuilder sb = new StringBuilder();
sb.Append("This is the first sentence.");
sb.AppendFormat("My name is {0} and I live in {1}", "Derek", "Pennsylvania");
sb.Replace("a", "e");
sb.Remove(5, 7);
Console.WriteLine(sb.ToString());
int[] randNumArr;
int[] randNum = new int[5];
int[] arr2 = { 1, 2, 3, 4, 5 };
Console.WriteLine("Where is 1 " + Array.IndexOf(arr2, 1));
string[] names = { "Tom", "Paul", "Sally" };
string nameStr = string.Join(",", names);
Console.WriteLine(names.ToString());
// exit
Console.ReadKey();
}
// LIST EXAMPLE
static void Main(string[] args)
{
List<int> numList = new List<int>();
numList.Add(5);
numList.Add(15);
numList.Add(25);
int[] array = { 1, 2, 3, 4, 5 };
numList.AddRange(array);
List<int> numList2 = new List<int>(array);
List<int> numList3 = new List<int>(new int[] { 1, 2, 3, 4 });
numList.Insert(1, 10);
numList.Remove(25); /*
numList.RemoveAt(2); */
for (int i = 0; i < numList.Count; i++)
Console.Write(numList[i] + " ");
Console.Write("\nList 2:\n");
for (int i = 0; i < numList3.Count; i++)
Console.Write(numList3[i] + " ");
Console.ReadKey();
}
// FILE EXAMPLE
static void Main(string[] args)
{
string[] custs = new string[] { "Tom", "Paul", "Greg" };
using (StreamWriter sw = new StreamWriter("custs.txt"))
{
foreach (string cust in custs)
sw.WriteLine(cust);
}
string custName = "";
using (StreamReader sr = new StreamReader("custs.txt"))
{
while ((custName = sr.ReadLine()) != null)
Console.WriteLine(custName);
}
Console.ReadKey();
}
No comments:
Post a Comment