Renaming a type in C # with a renamed type

using IdType = System.Guid;
using RowType = System.Tuple<System.Guid, object>

works. while

using IdType = System.Guid;
using RowType = System.Tuple<IdType, object>

not compiled.
IdTypedeclared in the first line cannot be used with a further one using, it seems.

Is there any way around this?

+4
source share
2 answers

This will work:

using IdType = System.Guid;
namespace x
{
    using RowType = System.Tuple<IdType, object>;
}

The reason that type aliases apply only to declarations in the namespace in which they are contained.

+11
source
using IdType = System.Guid;
using RowType = System.Tuple<System.Guid, object>;

namespace WindowsFormsApplication1
{
public void Test()
{
  var guideq = typeof(IdType).Equals(typeof(System.Guid));
  var typeeq=typeof(RowType).Equals(typeof(System.Tuple<System.Guid,
  object>));
  System.Tuple<System.Guid, object> obj = new RowType(IdType.NewGuid(), "");
}

IdType and System.Guid - this is the same type.

System.Tuple<System.Guid, object>and RowTypehave the same type. In this situation, it just works like an alias. Therefore, we need to use any place.

In the code, I test these two types for equality and that it is true; because it is an alias for the same type.

() , . , .

0

Source: https://habr.com/ru/post/1680212/


All Articles