473,385 Members | 1,587 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,385 software developers and data experts.

Macros in .NET

Hi all,

My application needs a macro which have scope in whole application
Is it possible to define a macro having global scope.

Thanks in advance.

Jul 22 '05 #1
2 1293
I believe you are refering to static classes/methods, etc. (Static classes in C# is a new 2.0 feature, from what I've seen in BETA
2)

I believe VB.NET already supports static classes, but they are called something different. (Modules, perhaps?)

Here's a 'static' example that works in any framework version (written in C#):

public namespace MyNamespace
{
public sealed class Math // sealed prevents other classes from inheriting "Math"
{
// private constructor prevents classes from creating an instance of "Math"
private Math()
{
}

public static int Add(int v1, int v2) // static keyword means that this method is 'shared' (VB keyword) amoung all
classes that it is visible to
{
return v1 + v2;
}
}
}

// example to use Math (notice, Math already exists in the framework, and is static, but does not have an Add method :)

public class Test
{
static void Main() // entry point to our application (notice, it is "static" which means an instance of "Test" is not
required)
{
// print '3':
Console.WriteLine(MyNamespace.Math.Add(1, 2));

// ^ didn't have to write new Math() to use the "Add" method
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
<so*************@yahoo.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com...
Hi all,

My application needs a macro which have scope in whole application
Is it possible to define a macro having global scope.

Thanks in advance.

Jul 22 '05 #2
<so*************@yahoo.com> wrote:
My application needs a macro which have scope in whole application
Is it possible to define a macro having global scope.


Macros are a language feature rather than a framework feature - what
language are you using? I expect managed C++ still has macros, but C#
doesn't. Not sure about VB.NET, but I expect it doesn't.

What kind of macro are you thinking of, anyway? Many macros are better
written as normal methods, potentially public static ones.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 22 '05 #3

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

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
8
by: Michael Winter | last post by:
In a recent post ("About C error" by Victor, 21 Sep 2003), comments were made about the poster's use of macros. What I would like to know is why they are considered bad? I'm not referring to...
11
by: Ben Hetland | last post by:
....in certain cituations they can be useful if not for anything else, then at least for saving a lot of repetetetetetitititive typing. :-) Beyond the point of "do something better instead", I'm...
3
by: Stephen Sprunk | last post by:
On a project I'm working on, I ran across the following macros: /* assume s is struct stream *, s->p is char, v is unit16_t or uint32_t */ #define in_uint16_le(s,v) { v = *((s)->p++); v +=...
47
by: Emil | last post by:
Is there any hope that new versions of PHP will support macros similar to C or C++? I've searched manual and didn't find anything except define directive, but it can be used to define constant...
11
by: San | last post by:
hi there, I am new to c++ and tryig to learn the basics of the c++ concepts. While I was reading the templates, I realize that the templates are a syntax that the compilar expands pased upon the...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.