클래스 개념
public class Point{
public int x,y;//변수(필드)
public Point()//생성자 함수(메소드)
{
}
}
//변수+메소드 -> member 변수,함수
public : 누구나 엑세스 가능
protected : 이 클래스 또는 이 클래스에서 파생된 클래스로만 액세스가 제한됨
internal : 현재 어셈블리(.exe, .dll등)로만 엑세스가 제한됨
protected internal : 포함하는 클래스, 포함하는 클래스에서 파생된 클래스 또는 동일한 어셈블ㄹ ㅣ내의 클래스로만 엑세스가 제한됨
private : 이 클래스로만 엑세스가 제한됨
privated protected : 포함하는 클래스 또는 동일한 어셈블리 내의 포함하는 유형으로 부터 파생된 클래스로만 액세스가 제한됨
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac_class
{
class AA
{
//멤버 변수..
int num1;//기본적으로는 private
public int num2, num3;
//멤버 함수..
public void Print() {
Console.WriteLine("aa: {0}, bb: {1}, cc: {2}", num1, num2, num3);
}
void PrintPrivate(){
//외부 접근 불가
Console.WriteLine("aa: {0}, bb: {1}, cc: {2}", num1, num2, num3);
}
}
class Program
{
static void Main(string[] args) {
AA aa = new AA();//객체 생성
aa.num1 = 10;//오류 prviate
aa.num2 = 100;
aa.num3= 1000;
aa.Print(); //aa.PrintPrivate는 오류
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac_Constructor
{
class AA
{
int a;
public AA() {
a = 0;
Console.WriteLine(" Call Constructor ");
Console.WriteLine(" a: {0}", a);
Console.WirteLine(" f: {0}", f);
}
public AA(int a, float f){//오버로딩
an = a;
af = f;
Console.WriteLine(" Call Constructor ");
Console.WriteLine(" a: {0}", a);
Console.WirteLine(" f: {0}", f);
}
~AA() { //소멸자
Console.WriteLine(" Call Destructor ");
}
}
class Program
{
static void Main(string[] args) {
//생성자
AA aa = new AA();
AA aaa = new AA(10);
AA aaaa = new AA(100,0.5f);
}
}
}