-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.cs
48 lines (40 loc) · 1.16 KB
/
struct.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;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
//structure is defined using struct keyword
//it cannot be inherit and inherited
//it cannot contain default constructor
// it doesnot support inheritance and abstraction
struct student
{
public string name ;
public string dept ;
}
struct alphas
{
public int x;
public int y;
}
class @struct
{
static void Main(string[] args)
{
//creating an object to structure class with new keyword
student s = new student();
Console.WriteLine(s.name);
Console.WriteLine(s.dept);
//creating an object to structure class without new keyword
alphas a;
// Console.WriteLine(a.x); --->error due to value doesn't assigned for variable
a.x = 10;
a.y = 20;
Console.WriteLine(a.x);
Console.WriteLine(a.y);
Console.ReadKey();
}
}
}