Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#에서 초기 바인딩이란 무엇입니까?

<시간/>

컴파일 시간 동안 함수와 객체를 연결하는 메커니즘을 초기 바인딩이라고 합니다. 정적 바인딩이라고도 합니다. C#은 정적 다형성, 즉 함수 오버로딩과 연산자 오버로딩을 구현하는 두 가지 기술을 제공합니다.

예제를 통해 함수 오버로딩에 대해 알아보자 -

동일한 범위에서 동일한 함수 이름에 대해 여러 정의를 가질 수 있습니다. 함수의 정의는 인수 목록의 인수 유형 및/또는 수에 따라 서로 달라야 합니다. 반환 유형만 다른 ​​함수 선언은 오버로드할 수 없습니다.

다음은 완전한 예입니다 -

using System;

namespace PolymorphismApplication {
   class Printdata {
      void print(int i) {
         Console.WriteLine("Printing int: {0}", i );
      }

      void print(double f) {
         Console.WriteLine("Printing float: {0}" , f);
      }

      void print(string s) {
         Console.WriteLine("Printing string: {0}", s);
      }

      static void Main(string[] args) {
         Printdata p = new Printdata();

         // Call print to print integer
         p.print(5);

         // Call print to print float
         p.print(500.263);

         // Call print to print string
         p.print("Hello C++");
         Console.ReadKey();
      }
   }
}

출력

Printing int: 5
Printing float: 500.263
Printing string: Hello C++