Skip to content

Commit 1896df7

Browse files
committedApr 17, 2020
-
0 parents  commit 1896df7

20 files changed

+1693
-0
lines changed
 

Diff for: ‎.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# OS generated files
2+
.DS_Store
3+
.DS_Store?
4+
._*
5+
.Spotlight-V100
6+
.Trashes
7+
Icon?
8+
ehthumbs.db
9+
Thumbs.db

Diff for: ‎Arrays and Strings.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//Rextester.Program.Main is the entry point for your code. Don't change it.
2+
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
9+
namespace Rextester
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
//Single Dimensional Array
16+
//a reference type that can store multiple values
17+
//can be accessed through indexing
18+
19+
//declaring it
20+
int[] myArray;
21+
22+
//initiating
23+
//as we declare it
24+
int[] myNewArray = new int[10]; //0-9 used to access
25+
26+
//indexes start at 0
27+
28+
//after declaring
29+
myArray = new int[5]; //0-4
30+
myArray[0] = 234;
31+
myArray[1] = 5;
32+
myArray[2] = 6;
33+
//myArray[5] = 9; DO NOT DO
34+
Console.WriteLine(myArray[0]);
35+
36+
//strings, chars, bool...whatever type can be stored in an array
37+
char[] myCharArray = new char[5];
38+
myCharArray[0] = 'h';
39+
myCharArray[1] = 'e';
40+
myCharArray[2] = 'l';
41+
myCharArray[3] = 'l';
42+
myCharArray[4] = 'o';
43+
44+
for(int i = 0; i < 5; i++)
45+
{
46+
Console.WriteLine(myCharArray[i]);
47+
}
48+
49+
//Strings
50+
//strings are an array of characters
51+
//we can access through indexing but cannot change them
52+
string myString = "hello";
53+
Console.WriteLine("The last letter of Hello is: " + myString[4]);
54+
55+
//BAD example
56+
// DO NOT DO! myString[0] = 'Y';
57+
58+
}
59+
}
60+
}

Diff for: ‎Classes.cs

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//Rextester.Program.Main is the entry point for your code. Don't change it.
2+
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
9+
namespace Rextester
10+
{
11+
//what are classes?
12+
//blueprints to creating an object
13+
//they allow the user to create their own type as objects
14+
public class Monster
15+
{
16+
//what can a class contain
17+
//data members - constants/variables
18+
//methods/functions
19+
20+
//public class - can be accessed anywhere on this project
21+
//public data members/methods- can be accessed anywhere where the class
22+
//was instantiated
23+
public string name_;
24+
public int size_;
25+
public const int legs_ = 2;
26+
27+
//private data members/methods - can ONLY be accessed in the class
28+
private int scare_;
29+
30+
//static data members/methods- apply to the entire class rather than
31+
//an instance of it
32+
public static int nMonsters_;
33+
34+
//default constructor -intiated all values
35+
public Monster()
36+
{
37+
name_ = "default";
38+
size_ = 20;
39+
scare_ = 10;
40+
nMonsters_++; //increment number of monsters
41+
}
42+
43+
//constructors
44+
public Monster(string name, int size, int scare)
45+
{
46+
name_ = name;
47+
size_ = size;
48+
scare_ = scare;
49+
nMonsters_++;
50+
}
51+
52+
//methods
53+
public void print()
54+
{
55+
Console.WriteLine("Monsters name: " + name_);
56+
Console.WriteLine("Monsters size: " + size_);
57+
Console.WriteLine("Monsters scare: " + scare_);
58+
}
59+
60+
}
61+
62+
public class Program
63+
{
64+
public static void Main(string[] args)
65+
{
66+
Monster Dinosour = new Monster();
67+
//public members
68+
Console.WriteLine(Dinosour.name_);
69+
//can be changed
70+
Dinosour.name_ = "Rex";
71+
Console.WriteLine(Dinosour.name_);
72+
73+
//change a const cannot be changed
74+
// exmaple -- Dinosour.legs_ = 3;
75+
76+
//private members cannot be accessed here
77+
// example -- Console.WriteLine(Dinosour.scare_);
78+
79+
Console.WriteLine(Monster.nMonsters_);
80+
//using non-default-constructor
81+
Monster Dragon = new Monster("Drako", 30, 25);
82+
Console.WriteLine(Dragon.name_);
83+
84+
//static check
85+
Console.WriteLine(Monster.nMonsters_);
86+
87+
Monster Zombie = new Monster("Zombie", 6, 8);
88+
//call print
89+
Zombie.print();
90+
Dragon.print();
91+
Dinosour.print();
92+
93+
Console.WriteLine(Monster.nMonsters_);
94+
}
95+
}
96+
}

Diff for: ‎Date And Time.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//Rextester.Program.Main is the entry point for your code. Don't change it.
2+
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
9+
namespace Rextester
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
//What is DateTime
16+
//a class that gives us access to date and time
17+
DateTime myDate = DateTime.Now;
18+
19+
DateTime mySecondDate = new DateTime(2000 ,12, 24);
20+
21+
//.ToString()
22+
Console.WriteLine(myDate.ToString());
23+
24+
//.ToShortDateString()
25+
Console.WriteLine(myDate.ToShortDateString());
26+
27+
//.ToShortTimeString()
28+
Console.WriteLine(myDate.ToShortTimeString());
29+
30+
//.ToLongDateString()
31+
Console.WriteLine(myDate.ToLongDateString());
32+
33+
//.ToLongTimeString()
34+
Console.WriteLine(myDate.ToLongTimeString());
35+
36+
//mathematical functions- add and subtracts
37+
Console.WriteLine(myDate.AddYears(5).ToShortDateString());
38+
39+
//subtract hours
40+
Console.WriteLine(myDate.AddHours(-6).ToLongTimeString());
41+
42+
//access
43+
//.month , .day .hours...so on
44+
Console.WriteLine(myDate.Month.ToString());
45+
46+
//Convers trings to DateTime
47+
//Parse
48+
DateTime testDate = DateTime.Parse("2000/12/24");
49+
Console.WriteLine(testDate.ToString());
50+
51+
//TimeSpan
52+
//Allows us to see what the time difference is between two dates
53+
//use Subtract
54+
//getting difference bettween today and testDate
55+
TimeSpan daysPassed = DateTime.Now.Subtract(testDate);
56+
Console.WriteLine(daysPassed.TotalDays);
57+
58+
}
59+
}
60+
}

Diff for: ‎Directories And Paths.cs

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
8+
//System.IO allows to read and write files and data streams
9+
//anything that has to do with files required system.IO
10+
11+
namespace Test1
12+
{
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
//USE The File Class
18+
19+
string path = @"C:\temp\testText.txt";
20+
string path2 = @"C:\temp\text.txt";
21+
22+
//File.Exists checks if there is a file of such name in such directory
23+
if (File.Exists(path))
24+
{
25+
26+
//File.Delete(path) deletes such file from the directory
27+
File.Delete(path);
28+
}
29+
30+
//File.WriteAllText()
31+
//creates the file, allows us to write to it and then closes the file
32+
//if the file exists it will replace it
33+
File.WriteAllText(path, "Hello!");
34+
35+
//File.WriteAllLines()
36+
//creates the file, allows us to write 1 or more lines and then closes the file
37+
//replaces existing files
38+
File.WriteAllLines(path2, new string[] { "Hello!", "This is kind of neat!" });
39+
40+
//editing the files -Appending to the files
41+
//File.AppendAllText()
42+
//opens file, appends to it and then closes it
43+
File.AppendAllText(path, " How's it going?");
44+
45+
//reading the file
46+
//File.ReadAllTexts returns a string
47+
string contents = File.ReadAllText(path2);
48+
Console.WriteLine("Contents is:" + contents);
49+
Console.WriteLine(File.ReadAllText(path));
50+
51+
//Direcotory - Folders
52+
53+
string dirPath = @"C:\temp\newDirectory";
54+
55+
//Cannot exists
56+
if (Directory.Exists(dirPath))
57+
{
58+
//Deleting
59+
//two ways
60+
//1 IF the directory is Empty
61+
//Directory.Delete(newPath);
62+
63+
//2 IF the directory ISNT empty
64+
Directory.Delete(dirPath, true);
65+
66+
}
67+
Directory.CreateDirectory(dirPath);
68+
69+
//Path Class
70+
//allow us to make changes to the string path that lead to directories or filess
71+
72+
string newPath = @"C:\temp\newDirectory\ourText.txt";
73+
74+
File.WriteAllText(newPath, "WOW this is really cool!");
75+
76+
//gets directory name
77+
string dirName = Path.GetDirectoryName(newPath);
78+
Console.WriteLine("Directory Name: " + dirName);
79+
80+
//gets file extension
81+
string fileExt = Path.GetExtension(newPath);
82+
Console.WriteLine("File Extension: " + fileExt);
83+
84+
//gets File Name
85+
string fileName = Path.GetFileName(newPath);
86+
Console.WriteLine("File Name: " + fileName);
87+
88+
//gets file name without extention
89+
string file_woExt = Path.GetFileNameWithoutExtension(newPath);
90+
Console.WriteLine("File Name/No Extension: " + file_woExt);
91+
92+
//get files root directory
93+
string root = Path.GetPathRoot(newPath);
94+
Console.WriteLine("Root Directory: " + root);
95+
96+
//change file extension
97+
string newFileRes = Path.ChangeExtension(newPath, ".new");
98+
Console.WriteLine("new File: " + newFileRes);
99+
100+
101+
Console.ReadKey();
102+
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)
Please sign in to comment.