첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Student.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 학생
    /// </summary>
    public unsafe struct Student
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region Field

        /// <summary>
        /// ID
        /// </summary>
        public int ID;

        /// <summary>
        /// 성명
        /// </summary>
        public fixed char Name[20];

        /// <summary>
        /// 생성 시간
        /// </summary>
        public DateTime CreateTime;

        #endregion
    }
}

 

728x90

 

▶ Program.cs

using System;
using System.Runtime.InteropServices;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 복사하기 - Copy(source, target)

        /// <summary>
        /// 복사하기
        /// </summary>
        /// <param name="source">소스 문자열</param>
        /// <param name="target">타겟 포인터</param>
        private unsafe static void Copy(string source, char* target)
        {
            char[] sourceCharArray = source.ToCharArray();

            Marshal.Copy(sourceCharArray, 0, new IntPtr(target), sourceCharArray.Length);
        }

        #endregion
        #region 문자열 구하기 - GetString(sourcePointer)

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <param name="sourcePointer">소스 포인터</param>
        /// <returns>문자열</returns>
        private unsafe static string GetString(char* sourcePointer)
        {
            return new string(sourcePointer);
        }

        #endregion

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private unsafe static void Main()
        {
            Student student = new Student();

            Copy("홍길동", student.Name);

            string name = GetString(student.Name);

            Console.WriteLine(name);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요