Typedef

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi.

I am looking something similar to typedef in C++ in C#. Basically, I have a
Person class. Then, I want to declare new type called Beneficiary using the
Person class.

I tried using the following:

using System;

namespace X
{
using Beneficiary = Person;
}

The problem with this is that it only works in the file scope. If I want to
use the class in other files, I have to declare them all over again.

I want to declare once in a file and use them other places just like the
other classes.

Thanks.
J
 
I am looking something similar to typedef in C++ in C#. Basically, I have
a
Person class. Then, I want to declare new type called Beneficiary using
the
Person class.

I tried using the following:

using System;

namespace X
{
using Beneficiary = Person;
}

The problem with this is that it only works in the file scope. If I want
to
use the class in other files, I have to declare them all over again.

I want to declare once in a file and use them other places just like the
other classes.

As I recall, that is pretty much identical to what typedef does...typedef's
are just included in header files, which is not supported. You are going to
have to include it in each file, but its not the design of using thats the
problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top