oo-70-245-1

oo-70-245-1 Commit Details


Date:2014-09-10 20:38:27 (10 years 1 month ago)
Author:Natalie Adams
Branch:master
Commit:39c97eb444e0a5c7dd9b5b5d5e0bd1a2684d7e17
Parents: 13f06a690083c0fb8378323f42102cb16d088f30
Message:Adding class example code from day 2

Changes:

File differences

Day 2 Class Examples/example10/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example10
{
class Program
{
class EvenInt
{
int val = 0;
public delegate void CallbackFun(int newval, int oldval);
public event CallbackFun Changed;
public int Value
{
get { return val; }
set
{
if (Changed != null)
Changed(value, val);
val = value;
}
}
}
static void Main(string[] args)
{
EvenInt num = new EvenInt();
num.Changed += new EvenInt.CallbackFun(num_Changed);
num.Changed += new EvenInt.CallbackFun(num_Changed2);
num.Value = 20;
num.Value += 10;
}
static void num_Changed2(int newval, int oldval)
{
Console.WriteLine("numchanged2");
}
static void num_Changed(int newval, int oldval)
{
Console.WriteLine("Changed from {0} to {1}", oldval, newval);
}
}
}
Day 2 Class Examples/example11/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example11
{
class Program
{
static void Main(string[] args)
{
int[] x = new int[10];
for (int i = 0; i < x.Length; i++)
x[i] = i;
foreach (int z in x)
Console.WriteLine(z);
List<int> lst1 = new List<int>();
for (int i = 0; i < 10; i++)
lst1.Add(i);
foreach (int z in lst1)
Console.WriteLine(z);
ArrayList al1 = new ArrayList();
for (int i = 0; i < 10; i++)
al1.Add(i);
foreach (int z in al1)
Console.WriteLine(z);
int w = (int)al1[0];
}
}
}
Day 2 Class Examples/example12/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example12
{
class MyException : Exception
{
public MyException(string msg) : base(msg)
{
}
}
class Program
{
static void Main(string[] args)
{
//throw new Exception("this is a boring exception");
throw new MyException("this is a fun exception");
}
}
}
Day 2 Class Examples/example6/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example6
{
internal class PassTest
{
public PassTest(int x) { }
public List<int> vals = new List<int>();
}
class Program
{
static void f1(int x)
{
x = 5;
}
static void f2(ref int x)
{
x = 5;
}
static void f3(PassTest t)
{
t.vals.Add(5);
}
static void f4(ref PassTest t)
{
t = new PassTest(5);
t.vals.Add(10);
}
static void Main(string[] args)
{
internalexamples.
int x = 4;
f1(x);
Console.WriteLine(x);
f2(ref x);
Console.WriteLine(x);
PassTest t = new PassTest(x);
Console.WriteLine(string.Join(",", t.vals.ToArray()));
f3(t);
Console.WriteLine(string.Join(",", t.vals.ToArray()));
f4(ref t);
Console.WriteLine(string.Join(",", t.vals.ToArray()));
}
}
}
Day 2 Class Examples/example7/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example7
{
class Program
{
class Example
{
private int test1;
public int test2;
protected int test3;
public virtual void func(int x) { }
private void func2() { }
}
class Ex2 : Example
{
public override void func()
{
base.func(x);
}
}
static void Main(string[] args)
{
Example e = new Example();
e.test2 = 2;
}
}
}
Day 2 Class Examples/example9/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace example9
{
class DisposeTest : IDisposable
{
public void Dispose()
{
Console.WriteLine("Cleaning up DisposeTest");
}
}
class DestructTest
{
~DestructTest()
{
Console.WriteLine("Cleaning up DestructTest");
}
}
class Program
{
static void Main(string[] args)
{
{
DestructTest t2 = new DestructTest();
}
//GC.Collect(3, GCCollectionMode.Forced);
Console.WriteLine("top");
using (DisposeTest t = new DisposeTest())
{
}
Console.WriteLine("bottom");
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.11612s using 14 queries.