473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Type equivalence/identity

In C# is there a way to alias or equivalence one type to another?

For example, in Delphi, I can say...

type TMyFloat = type double;

and then cheerfully use TMyFloat in my field definitions, return
value declarations for functions, declaring variables and formal
procedure/function/method arguments. If at a later time -double-
turns out to be a suboptimal choice I can change the lone type
declaration to say....

type TMyFloat = type Extended;

and recompile without having to change all of the declarations
elsewhere in my application.

I could subclass non-sealed classes to achieve something like this
but for C#'s sealed supplied classes, like changing my mind to
use Decimal instead of double, I can't think of a way.

Any ideas?

Oz
Nov 15 '05 #1
2 2367
You can use 'using' to alias namespaces in addition to Types:

namespace MyNamespace.Using
{
class A {}
}
namespace SomeNamespace
{
using MyAlias = MyNamespace.Using;
class B: MyAlias.A {}
}

Martha
"Alvin Bruney" <.> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
You can use the following for aliases in C#.
Using SomeNewAlias = System.Int32;


"ozbear" <oz*****@yahoo.com> wrote in message
news:3fb56482.306663406@news-server...
In C# is there a way to alias or equivalence one type to another?

For example, in Delphi, I can say...

type TMyFloat = type double;

and then cheerfully use TMyFloat in my field definitions, return
value declarations for functions, declaring variables and formal
procedure/function/method arguments. If at a later time -double-
turns out to be a suboptimal choice I can change the lone type
declaration to say....

type TMyFloat = type Extended;

and recompile without having to change all of the declarations
elsewhere in my application.

I could subclass non-sealed classes to achieve something like this
but for C#'s sealed supplied classes, like changing my mind to
use Decimal instead of double, I can't think of a way.

Any ideas?

Oz


Nov 15 '05 #2
Ignore this guy he is spoofing my email account. For credibility purposes I
suppose.

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Alvin Bruney" <.> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
You can use the following for aliases in C#.
Using SomeNewAlias = System.Int32;


"ozbear" <oz*****@yahoo.com> wrote in message
news:3fb56482.306663406@news-server...
In C# is there a way to alias or equivalence one type to another?

For example, in Delphi, I can say...

type TMyFloat = type double;

and then cheerfully use TMyFloat in my field definitions, return
value declarations for functions, declaring variables and formal
procedure/function/method arguments. If at a later time -double-
turns out to be a suboptimal choice I can change the lone type
declaration to say....

type TMyFloat = type Extended;

and recompile without having to change all of the declarations
elsewhere in my application.

I could subclass non-sealed classes to achieve something like this
but for C#'s sealed supplied classes, like changing my mind to
use Decimal instead of double, I can't think of a way.

Any ideas?

Oz


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of...
2
by: Alex Drummond | last post by:
Hello, Is there any way of specializing a templated function on a type which is itself templated? Here's the simplest example of the problem I can think of. Say I have written an implementation...
1
by: Kenneth P | last post by:
Hi, I'm trying to do some Custom Paging technique with the datagrid object and with the select command in Sql, thus forcing the server to only select those rows from the database that should be...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
5
by: The Eclectic Electric | last post by:
I'm very noobish when it comes to Javascript, in fact I wasn't intending to use it at all, but I've got myself distracted by this "problem". I want to use an animated gif as my favicon. This...
3
by: Martin | last post by:
Hi. I need to identify the type of the exception in the universal handler (catch (...)) for debugging purposes. Point is that I write a testing console application, which must call some...
20
by: =?Utf-8?B?ZW1pdG9qbGV5ZXM=?= | last post by:
Hi everyone: i read from the documentation of a dll that there is a struct that uses char for storing an IP address. How can it be? and how come i can get to representate the same value in a...
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.