2013년 9월 2일 월요일

닷넷 using에서 type name 충돌 해결법

using에서 type name 충돌 해결법

 namespace My2DShapes
{
  public class Hexagon{}
}

namespace My3DShapes
{
  public class Hexagon{}
}
Now assume you wish to create an instance of the 3D Hexagon from the following application:

using My2DShapes;
using My3DShapes;

public class MyApp
{
  public static void Main()
  {
    // Error!  Which Hexagon?
    Hexagon h = new Hexagon();   
  }
}
This name clash can be resolved quite simply by building the following alias:

using My2DShapes;
using The3DHex = My3DShapes.Hexagon;

public class MyApp
{
  public static void Main()
  {
    // This really creates a new My3DShapes.Hexagon.
    The3DHex h = new The3DHex();   
  }
}


오라클자바커뮤니티 추천 실무 강좌

C#,ASP.NET마스터 8일 56시간   09-05
C#,ASP.NET마스터 18일 54시간   09-06
C#,ASP.NET마스터 8일 56시간   09-07

댓글 없음:

댓글 쓰기