Create a dynamic FILO queue ( a stack ).

J

Jeff Relf

Hi WHY,

You tapped out: <<
Since there's no way to create a c# method with optional,
or nullable parameters. >>

No sprintf ( char * Format, ... ) ?

You added: <<
And since you can't write an overloaded web method. >>

Could that be true ? I don't believe it.

You asked: <<
Is it possible to edit the WSDL [ .XML file ]
in conjunction with a c# method
to make the parameter optional,
or have a default value at the client consumer ? >>

Perhaps you could emulates sprintf() by parsing
a string that tells you what parameters are on the stack...

What's a stack ? I hear you asking.

It's a dynamic FILO queue, First In Last Out.

You could create a dynamic FILO queue via a dynamic array,
with pointers to the top and the bottom of the stack.

Of course I would use realloc() to manage a dynamic array...

But I think C#'s automatic allocations
could do something similar... perhaps using the VAR type.
 
T

Thomas Edison

But I think C#'s automatic allocations
could do something similar... perhaps using the VAR type.

..NET has a Stack class:

Stack s = new Stack();
s.Push(42);
int i = (int)s.Pop();
 
J

Jeff Relf

Hi Thomas Edison,

You mentioned: << .NET has a Stack class:
Stack s = new Stack(); s.Push(42);
int i = (int)s.Pop(); >>

How would that Stack class be added in C# or C++ ?

In C/C++ I would do something like this:
#include <Something.H> // Something.LIB
 
T

Tom Shelton

Hi Thomas Edison,

You mentioned: << .NET has a Stack class:
Stack s = new Stack(); s.Push(42);
int i = (int)s.Pop(); >>

How would that Stack class be added in C# or C++ ?

In C/C++ I would do something like this:
#include <Something.H> // Something.LIB


Well, the stack class is in the System.Collections namespace - but that
resides in System.dll so, you don't actually have to do anything to add
it. If you want to access it with an unqualified name you have to place
a using statement in the file:

using System.Collections;
....

Stack stack = new Stack();

Other wise you would have to write the code like this:

System.Collections.Stack stack = new System.Collections.Stack();
 
J

Jeff Relf

Hi Tom Shelton,

Re: System.Collections.Stack stack
= new System.Collections.Stack();

Upon compiling that in a .CPP file, I got this error:

'System' : undeclared identifier

Re: using System.Collections;

That give me the following errors:

1. missing ';' before '.'

2. 'System' cannot be used in a using-declaration
 
T

Thomas Edison

Hi Tom Shelton,

Re: System.Collections.Stack stack
= new System.Collections.Stack();

Upon compiling that in a .CPP file, I got this error:

That's C#/.NET code. :)
 
D

Daniel O'Connell [C# MVP]

Jeff Relf said:
Hi Tom Shelton,

Re: System.Collections.Stack stack
= new System.Collections.Stack();

Upon compiling that in a .CPP file, I got this error:

'System' : undeclared identifier

Re: using System.Collections;

That give me the following errors:

1. missing ';' before '.'

2. 'System' cannot be used in a using-declaration

For managed C++ you have to write
using namespace System::Collections;
If memory serves.
 
D

Daniel O'Connell [C# MVP]

Jeff Relf said:
Hi WHY,

You tapped out: <<
Since there's no way to create a c# method with optional,
or nullable parameters. >>

No sprintf ( char * Format, ... ) ?

Different concept. ... is analgous to the params keyword in C#

public void sprintf(string format, params string[] parameters);

would work. However, its not the same as a VB optional parameter or an SQL
style nullable type. C# gains the latter in 2.0.

I do'nt know if params maps to WSDL or not.
You added: <<
And since you can't write an overloaded web method. >>

Could that be true ? I don't believe it.

WSDL works based on names, you cannot create overloads because the message
name determines which method is called. Two methods with teh same name
clash. I don't know the specifics but there is an attribute that will allow
you to change the method name.
Of course I would use realloc() to manage a dynamic array...

But I think C#'s automatic allocations
could do something similar... perhaps using the VAR type.

There *is* no VAR type, please learn the langauge before responding, -_-.
ArrayList, Stack, Queue, etc handle it for you. There is no simple
reallocation operation like C provides as it isn't always really logical to
do so, writing a dynamic array class isn't terribly hard, even if it is a
waste of time.
 
J

Jeff Relf

Hi Thomas Edison,

Re: How System.Collections.Stack
is not available for .CPP files,

Thanks.

That makes sense,
kind of like how C# doesn't support realloc()
and memmove().
 
J

Jeff Relf

Hi Jessup Silstrom,

Re: C# not supporting realloc() and memmove().

You asked, <<
Why would a language with automatic garbage collection
need to do this ? >>

Even if supporting functions that
have been around for decades
means absolutely nothing to you...

realloc() and memmove() provide much more
control over how memory gets allocated, used
and reclaimed.

But then you've never used those 2 routines, have you.
 
T

Tom Shelton

Hi Thomas Edison,

Re: How System.Collections.Stack
is not available for .CPP files,

Thanks.

That makes sense,
kind of like how C# doesn't support realloc()
and memmove().

// You can work with unmanaged memory....

using System.Runtime.Interop.Services;

....

IntPtr memPtr = Marshal.AllocHGlobal (numberOfBytesRequired);

....

// Oh, I need to realloc it...
memPtr = Marshal.ReallocHGlobal (memPtr, theNewSize);

....

// Ok, were done...
Marshal.FreeHGlobal (memPtr);

Nothing, exactly equivalent to memmove (at least in the unmanaged sense) -
but, you could implement it your self, or just make a call to the C runtime
to access the call dynamically. But all of this is almost never necessary.
 
T

Tom Shelton

Hi Tom Shelton,

Re: System.Collections.Stack stack
= new System.Collections.Stack();

Upon compiling that in a .CPP file, I got this error:

'System' : undeclared identifier

Re: using System.Collections;

That give me the following errors:

1. missing ';' before '.'

2. 'System' cannot be used in a using-declaration

This is C#. You asked how you would access the Stack class from C# - I
gave an example.
 
J

Jeff Relf

Hi Tom Shelton,

Re: The .NET SDK,

You wrote: << Nothing, exactly equivalent to memmove()
( at least in the unmanaged sense ) -
but, you could implement it your self,
or just make a call to the C runtime
to access the call dynamically.
But all of this is almost never necessary. >>

I use memmove() all the time.

Also, I question the quality of any virtual OS like .NET,

What's wrong with using Win XP directly ?
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top