'분류 전체보기'에 해당되는 글 24건

  1. 2015.08.02 what is 'w' component on Vector4
  2. 2015.06.22 c# 의 new키워드에 대해
  3. 2015.06.12 Action, Func 콜백 예시
  4. 2015.05.29 c# where
  5. 2015.05.28 GetComponentsInChildren overload
2015. 8. 2. 11:37

http://gpgstudy.com/forum/viewtopic.php?p=126354


동차성분, transration을 표현하기위한.. dx할때 배운건데 까먹었었네

Posted by 반얀
2015. 6. 22. 15:00



-------------------------------------------------------------------------------------


c++은 모두 value type


c#은 type이 지정되어있다


c++은 사용자가 필요에 따라 포인터라는 기능을 사용해 메모리 위치를 정할수있지만


c#은 닷넷에서 알아서 분배해서 reference type은 아예 할당안하면 에러나고 그럼


즉 c++ 에서는 


class AAA

{}


void main()

{

AAA aaa;

aaa.test();


AAA aaa = new AAA();

aaa->test();

}

이런식으로 정적할당할지 동적할당할지 정할수 있었다. 모든것이 value type이기 때문


하지만 c#에서는 애초에 reference type인것은 무조건 동적할당을 해줘야 사용가능하다는 말임



-------------------------------------------------------------------------------------

issue about 'new ' keyword


[원문]http://stackoverflow.com/questions/23034541/operator-new-in-c-sharp-vs-c


변수, 객체 할당에 대한 내용

간단히 번역만 해둠


3가지 경우가 있다 1. 지역변수 

 2. (non-static)구조체 멤버변수

 3. 클래스 멤버변수


1.지역변수

class C

{

  void M()

  {

    Foo fooInstance = new Foo();

    //definite assignment - 접근해서 사용가능

    // the variable is "definitely assigned" and can be read (copied, passed etc)

    // consider using the 'var' keyword above!

  }

}


class C

{

  void M()

  {

    Foo fooInstance;

    // 이건 안됨. 접근 불가.  할당후에 사용가능함

    // the variable is not "definitely assigned", you cannot acquire its value

    // it needs to be assigned later (or can be used as 'out' parameter)

  }

}



2.(non-static)구조체 멤버변수

struct S

{

  Foo fooInstance = new Foo(); // compile-time error! cannot initialize here

       // 선언시 할당 불가

}


struct S

{

  Foo fooInstance; // OK, access level is 'private' when nothing is specified

                      // 특별히 접근제한자 안걸면 private으로 사용가능

}



3. 클래스 멤버변수

class C

{

  Foo fooInstance = new Foo(); // OK, private

}


class C

{

  Foo fooInstance; // OK, private

  // equivalent to 'Foo fooInstance = null;' if 'Foo' is a reference type (class, interface, delegate, array)

  // equivalent to 'Foo fooInstance = new Foo();' is 'Foo' is a value type (struct, enum) <- 이부분이 궁금함

아아 value 타입인경우 그냥 쓰나 이니셜라이저 사용하나 똑같다는 말임


 애초에 값이 reference타입인지 value타입인지 정해져있으면 new 키워드를 붙여도 무조건 그에 따라 스택 힙 결정되는건가

}


'C#/Unity' 카테고리의 다른 글

2D OthographicSize  (0) 2016.04.10
NGUI Drawcall  (0) 2015.09.15
Action, Func 콜백 예시  (0) 2015.06.12
c# where  (0) 2015.05.29
GetComponentsInChildren overload  (0) 2015.05.28
Posted by 반얀
2015. 6. 12. 17:36

다 찾아서 정리좀 하자


System.Action<T> T가 이 delegate의 매개변수



delegate는 따로 정리하자


Action, Func는 오버로드된 delegate들의 모음들?이라고 보면될듯


Action은 return값이 없는 delegate, Func는 return값을 갖는 delegate이다


Action, Action<T>, ~ Action<T, ......> 이런식으로 매개변수가 없는 것부터 여러개 가진것까지 다양하게 제공되어져있다.


여러가지 필요에 따라 사용할 수 있겠지만 이번에는 콜백용도로 사용하는 예시를 보이겠다.


문법은 그냥 슈도코드처럼 알아볼수있게만 쓰도록하겠음 컴파일러없이 그냥 쓰는건 익숙치가않아서..


class BBB

{

//이 함수는 클릭, 키입력등 특정 입력값 발생시 호출되는 함수로 가정하겠음

//매개변수 입력도 이 때 받게됨

public void Calculate(int a, int b)

{

print( "첫번째 입력 :" + a + " , " + "두번째 입력 :" + b + ", 두 수의 합은 " + (a + b));

}

}


class AAA

{

public void ShowCalculateBBB()

{

//여기서 BBB.Caculate()의 결과를 내가 원하는 때에 ShowCaclulateBBB()함수 호출을 통해 보고싶다면

}

}


BBB.Calculate가 호출될때가 아니라 내가 의도한 때에 AAA.ShowCalculateBBB를 통해 보고싶다면 어찌해야할까

방법은 여러가지있겠지만 여기선 람다식과 Action을 통해 사용하는 한가지 방법을 보이겠다.


class BBB

{

//이 함수는 클릭, 키입력등 특정 입력값 발생시 호출되는 함수로 가정하겠음

//매개변수 입력도 이 때 받게됨

public void Calculate(int a, int b)

{

AAA._receiveAction =

() =>

{

print( "첫번째 입력 :" + a + " , " + "두번째 입력 :" + b + ", 두 수의 합은 " + (a + b));

}

}

}


class AAA

{

public System.Action = _receiveAction; 



//BBB.Calculate가 호출된 시점에  _receiveAction에 원하는 시퀀스가 저장되고

//그 시퀀스를 원하는 시점에 AAA.ShowCalculateBBB()를 통해 진행할수있다.

//만약 Action<T..>같이 매개변수를 둔다면 그 매개변수의 참조값을 가져와 접근도 가능하다

public void ShowCalculateBBB()

{

_receiveAction();

}

}


이런식으로 Action변수에 등록해놓는 방식으로 꺼내쓸수있다. 


또 Action<object> 형으로 선언하면 박싱/언박싱 이슈가 있을 수 있지만 어떤 형을 인자로 사용하든 활용가능하다는 장점이 있다.


나중에 더 좋은 예시를 추가할것임



'C#/Unity' 카테고리의 다른 글

NGUI Drawcall  (0) 2015.09.15
c# 의 new키워드에 대해  (0) 2015.06.22
c# where  (0) 2015.05.29
GetComponentsInChildren overload  (0) 2015.05.28
delegate, callback  (0) 2015.05.08
Posted by 반얀
2015. 5. 29. 11:01

public class MainClass

{

}


//MiddleClass<T>는 MainClass를 상속받으며 Generic T의 형식은 MiddleClass<T>로 한정한다.

public class MiddleClass<T> : MainClass where T : MiddleClass<T>

{

}


public class LowClass : MiddleClass<LowClass>

{


where T는 T의 형식을 제한할때 사용함


https://msdn.microsoft.com/ko-kr/library/bb384067.aspx

'C#/Unity' 카테고리의 다른 글

c# 의 new키워드에 대해  (0) 2015.06.22
Action, Func 콜백 예시  (0) 2015.06.12
GetComponentsInChildren overload  (0) 2015.05.28
delegate, callback  (0) 2015.05.08
arraylist list 차이  (0) 2015.05.06
Posted by 반얀
2015. 5. 28. 16:30

다 써본건 아니고


T[] tests = GetComponentsInChildren<T>();


이면 enable된거만 배열에 등록되고


T[] tests = GetComponentsInChildren<T>( true);


이면 include inactive라고 인텔리센스에 나오는데 말 그대로 enabled건 disabled건 다 배열에 때려넣는다.


T[] tests = GetComponentsInChildren<T>(false);


이건 맨 기본형과 기능이 같으니까 의미없는듯


2개 더있는데 써보진않았다

'C#/Unity' 카테고리의 다른 글

Action, Func 콜백 예시  (0) 2015.06.12
c# where  (0) 2015.05.29
delegate, callback  (0) 2015.05.08
arraylist list 차이  (0) 2015.05.06
Unity 원하는 객체(클래스)를 인스펙터창에서 만질수 있도록  (0) 2015.04.20
Posted by 반얀