//NOTES: STRUCT
// - struct is a value type
// - no need to use new keyword
// - cannot inherit from struct(error: cannot derive from sealed type)
// - struct allows properties/method which uses reference type.
namespace StructSample
{
class Program
{
static void Main(string[] args)
{
Point p;
p.x = 10;
p.y = 20;
p.name = "wgi";
Console.WriteLine(p.Add());
Console.Read();
}
}
struct Point
{
public int x, y;
public string name;
public int Add() { return x + y; }
}
//class newPoint : Point
//{
//}
}
// - struct is a value type
// - no need to use new keyword
// - cannot inherit from struct(error: cannot derive from sealed type)
// - struct allows properties/method which uses reference type.
namespace StructSample
{
class Program
{
static void Main(string[] args)
{
Point p;
p.x = 10;
p.y = 20;
p.name = "wgi";
Console.WriteLine(p.Add());
Console.Read();
}
}
struct Point
{
public int x, y;
public string name;
public int Add() { return x + y; }
}
//class newPoint : Point
//{
//}
}
No comments:
Post a Comment