-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct_vs_classes.cs
44 lines (37 loc) · 1.06 KB
/
struct_vs_classes.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
using System;
namespace classes_vs_structs
{
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
//System.Int32 i = 0;
/*if (i == 10)
{
int j = 20;
Customer c1 = new Customer();
c1.ID = 101;
c1.Name = " Mark";
}*/
int i = 10;
int j = i;
j += 1;
Console.WriteLine("I = {0}, J = {1}",i,j);
Customer c1 = new Customer();
c1.ID = 101;
c1.Name = "Mark";
Customer c2 = c1;
c1.Name = "Mary";
Console.WriteLine("c1.Name = {0} c2.Name = {1}",c1.Name,c2.Name);
//classes can have distructors structs cannot
//structs cannot have parametersless constructors
//a struct or class cannot inherit from another struct
//sealed classes cannot be inherited.
}
}
}