A C# 6.0 Language Preview


참조 URL
  1. http://msdn.microsoft.com/en-us/magazine/dn683793.aspx

 


example





MS 요즘 빠른 행보와 C# 6.0 버전이 출시를 할거 같습니다.
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

 

A C# 6.0 Language Preview

http://msdn.microsoft.com/en-us/magazine/dn683793.aspx

 

중에 프로퍼티의 선언과 초기화가 좀더 단순화 있도록 개선이 되네요

 

지금까지는 private public 변수를 각각 선언해서 초기화를 시켰는데 아래와 같이 초기화를 한줄로 있을 합니다.

 

 

 

Auto-Properties with Initializers

Initializing a class today can be cumbersome at times. Consider, for example, the trivial case of a custom collection type (such as Queue<T>) that internally maintains a private System.Collections.Generic.List<T> property for a list of items. When instantiating the collection, you have to initialize the queue with the list of items it is to contain. However, the reasonable options for doing so with a property require a backing field along with an initializer or an else constructor, the combination of which virtually doubles the amount of required code.


With C# 6.0, there’s a syntax shortcut: auto-property initializers. You can now assign to auto-properties directly, as shown here:


1.      class Queue<T>

2.      {

3.        private List<T> InternalCollection { get; } = 

4.          new List<T>; 

5.        // Queue Implementation

6.        // ...

7.      }

 

 

 

그리고 JSON Data 쉽게 다룰 있는 JObject라는 타입이 새로 나왔습니다.

 

 

 

Figure 3 Leveraging the Indexed Method with JSON Data

1.      using Microsoft.VisualStudio.TestTools.UnitTesting;

2.      using Newtonsoft.Json.Linq;

3.      // ...

4.      [TestMethod]

5.      public void JsonWithDollarOperatorStringIndexers()

6.      {

7.        // Additional data types eliminated for elucidation

8.        string jsonText = @"

9.          {

10.        'Byte':  {

11.          'Keyword':  'byte',

12.          'DotNetClassName':  'Byte',

13.          'Description':  'Unsigned integer',

14.          'Width':  '8',

15.          'Range':  '0 to 255'

16.                  },

17.        'Boolean':  {

18.          'Keyword':  'bool',

19.          'DotNetClassName':  'Boolean',

20.          'Description':  'Logical Boolean type',

21.          'Width':  '8',

22.          'Range':  'True or false.'

23.                    },

24.      }";

25.    JObject jObject = JObject.Parse(jsonText);

26.    Assert.AreEqual("bool", jObject.$Boolean.$Keyword);

27.  }

 



총 10가지 정도가 프리뷰에서 보여졌는데요. 그 중에 크게 변한 2가지 부분을 우선 소개하고 좀더 자세한 사항은 링크를 타고 들어가서 확인하시면 될거 같습니다.





 








손 코딩 뇌 컴파일 눈 디버깅


참조 URL
  1. 손코딩뇌컴파일눈디버깅
  2. http://www.slideshare.net/kwangswei/ss-30510586
  3. http://community.topcoder.com/
  4. http://kwangswei.tistory.com/421

 


 논리적인 사고와 문제 해결능력을 배양 시키는 방법을 소개하고 있다. 손으로 코딩하고 뇌로 컴파일하고 눈으로 디버깅을 하는 연습으로 자신의 능력을 배양 할 수 있을것이다.














C#에서 Enum 타입을 다중값으로 활용 - Flags


참조 URL
  1. http://msdn.microsoft.com/ko-kr/library/cc138362.aspx
  2. http://msdn.microsoft.com/en-us/library/system.enum.hasflag(v=vs.110).aspx
  3. http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c

 


 C#에서 Enum 타입으로 선언해서 프로그래밍을 할 때 하나의 값 대신 복수의 상태를 표시해야 할 때 사용할 수 있는 방법입니다. Enum을 선언시 아래와 같이 Attribute를 달아주면 복수의 상태를 사용할 수 있는 상태가 됩니다.



[코드1] Enum 선언과 사용 방법 ( OR 연산으로 값 추가 )



 위와 같이 선언하고 사용할 수 있으며 선언된 값을 판단하여 사용하는 방법은 아래와 같습니다.


[코드2] & 연산으로 값 비교




[코드3] XOR 연산으로 값 해제




example

[코드4] 다른 방식으로 선언 방법



[코드] 또 다른 선언 방법










 








+ Recent posts