오늘의 C# 공부 :

////무명 형식
//using System;

//namespace AnonymousType
//{
//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            var a = new { Name = “박상현”, Age = 123 };
//            Console.WriteLine(“Name : {0}, Age : {1}”, a.Name, a.Age);

//            var b = new { Subject = “수학”, Scores = new int[] { 90, 80, 70, 60 } };
//            Console.Write(" Subject : {0} , Scores : “, b.Subject);
//            foreach (var scores in b.Scores)
//                Console.Write("{0}  “, scores);
           
//            Console.WriteLine();
//        }
//    }
//}

////인터페이스의 프로퍼티
//using System;

//namespace PropertiesInInterface
//{
//    interface INameValue
//    {
//        string Name
//        {
//            get;
//            set;
//        }

//        string Value
//        {
//            get;
//            set;
//        }
//    }

//    class NameValue : INameValue
//    {
//        public string Name
//        {
//            get;
//            set;
//        }

//        public string Value
//        {
//            get;
//            set;
//        }
//    }

//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            NameValue name = new NameValue()
//            { Name = “이름”, Value = “박상현” };

//            NameValue height = new NameValue()
//            { Name = “키”, Value = “177”};

//            NameValue weight = new NameValue()
//            { Name = “몸무게”, Value = “90kg”};

//           Console.WriteLine("{0} : {1}” , name.Name , name.Value);
//            Console.WriteLine("{0} : {1}” , height.Name, height.Value);
//            Console.WriteLine("{0} : {1}" , weight.Name , weight.Value);

//        }
//    }
//}

////추상 클래스와 프로퍼티

//using System;
//namespace PropertiesInAbstractClass
//{
//    abstract class Product
//    {
//        private static int serial = 0;
//        public string SerialID
//        {
//            get { return String.Format("{0:d5}", serial++); }
//        }

//        abstract public DateTime ProductDate
//        {
//            get;
//            set;
//        }
//    }

//    class MyProduct : Product
//    {
//        public override DateTime ProductDate
//        {
//            get;
//            set;
//        }
//    }

   
   
//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            Product product_1 = new MyProduct() { ProductDate = new DateTime(2010, 1, 10) };

//            Console.WriteLine(“Product : {0} , Product Date : {1}”,
//                product_1.SerialID,
//                product_1.ProductDate);

//            Product product_2 = new MyProduct() { ProductDate = new DateTime(2010, 2, 3) };

//            Console.WriteLine(“Product : {0} , product Date : {1}”,
//                product_2.SerialID,
//            product_2.ProductDate);

//        }
//    }
//}

////배열과 컬렉션, 그리고 인덱서
//using System;

//namespace ArarrySample
//{
//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            int[] scores = new int[5];

//            scores[0] = 80;
//            scores[1] = 74;
//            scores[2] = 81;
//            scores[3] = 64;
//            scores[4] = 55;

//            foreach (int score in scores)
//            {
//                Console.WriteLine(score);
//            }

//            int sum = 0;
//            foreach (int score in scores)
//                sum += score;

//            int average = sum / scores.Length;

//            Console.WriteLine(“Average Score ; {0} “, average);
//        }
//    }
//}

////배열을 초기화하는 세 가지
//using System;

//namespace InitializingArray
//{
//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            string[] array1 = new string[3] { “안녕”, “Hello”, “Halo” };

//            Console.WriteLine(“array1…”);
//            foreach ( string greeting in array1)
//                Console.WriteLine("{0}",greeting);
           
           
//            string[] array2 = new string[] { “안녕”, “Hello”, “Halo” };

//            Console.WriteLine(“array2….”);
//            foreach (string greeting in array2)
//                Console.WriteLine("{0}”, greeting);

//            string[] array3 = { “안녕”, “Hello”, “Halo” };

//            Console.WriteLine(“array3…”);
//            foreach ( string greeting in array3)
//                Console.WriteLine ("{0}”, greeting);               
//        }
//    }
//}

////system.array

//using System;

//namespace DerivedFromArray
//{
//    class jpcorp
//    {
//        static void Main(string[] args)
//        {
//            int[] array = new int[] { 10, 30, 20, 7, 1 };
//            Console.WriteLine(“Type Of Array : {0}”, array.GetType());

//            Console.WriteLine(“Base type Of Array : {0} “, array.GetType().BaseType);
//        }
//    }
//}

//정적 메소드와 인스턴스 메소드
using System;

namespace MoreInArray
{
    class jpcorp
    {
        private bool CheckPassed(int score)// 인스턴스 메소드
        {
            if (score >= 60)
                return true;
            else
                return false;
        }

        private static void Print(int value) // 정적 메소드
        {
            Console.Write("{0} “, value);
        }

        static void Main(string[] args)
        {
            jpcorp jp = new jpcorp();// 인스턴스 메소드 사용하는 방법
            int[] scores = new int[] { 80, 74, 81, 90, 34 };

            foreach (int score in scores)
                Console.Write("{0} “, score);
            Console.WriteLine();

            Array.Sort(scores);
            Array.ForEach(scores, new Action(Print));
            Console.WriteLine();

            Console.WriteLine(“Number of dimensions : {0}”, scores.Rank);

            Console.WriteLine(“Binary Search : 81 is at {0} " , Array.BinarySearch (scores, 81));

            Console.WriteLine(“Linear Search : 90 is at {0} “, Array.IndexOf(scores, 90));

            Console.WriteLine(“Everyone passed? : {0}”, Array.TrueForAll(scores, jp.CheckPassed));

            int index = Array.FindIndex(scores, delegate(int score)
            {
                if (score < 60)
                    return true;
                else
                    return false;
            });

            scores[index] = 61;

            Console.WriteLine(“Everyone passed? : {0}”,
                Array.TrueForAll(scores, jp.CheckPassed));

            Console.WriteLine(“Old length of scores : {0} “, scores.GetLength(0));

            Array.Resize(ref scores, 10);

            Console.WriteLine(“New length of scores : {0} “, scores.Length);

            Array.ForEach(scores, new Action(Print));
            Console.WriteLine();

            Array.Clear(scores, 3, 7);

            Array.ForEach(scores, new Action(Print));
            Console.WriteLine();

        }
    }
}

Hugo로 만듦
JimmyStack 테마 사용 중