Couple of newbie questions...

C

Carlo Razzeto

Hey there, I'm a bit of a C# newbie and I have some questions regarding
syntax.

#1: Unsafe code blocks:

From what I understand (based on what I've read from the C# Essentials
O'Reilly book) memory managment in C# unsafe code blocks are handled almost
in good old C++ way (i.e. memory allocations don't go away unless you tell
them to). The one thing I didn't see mentioned in the book is what you use
to deallocate memory. So what do I call to deallocate memory, take the
following example for instace (C++ syntax used)

string *temp = new string[100];

What would be analogous to:

delete temp;

#2: Libraries.

I was thinking about building up a general usage library for web
programming. What I would love is to have, for instance one base namespace
that can be included and would give the programmer access to various classes
and methods. I already know how to create namespaces and classes with in
namespaces... What I would like to know is if there is a way to attach a
method to a name space, out side of a class. There are a few functions where
it would simply be more conviniant for me to not have them be attached to
any class.

Thanks for any help.
 
R

Richard A. Lowe

#1: Unsafe blocks are still managed by the runtime so memory allocated in
normal .NET ways (i.e. using class constructors and not using the Marshal
class to get a pointer to a chunk of unmanaged memory) will still be managed
by the runtime. There is no way to write *unmanaged* code in C# and unsafe
!= unmanaged.

#2 There's no way to bring a method into a namespace, but is it really so
inconvenient to preface a method call with a class or instance name?

Richard
 
C

Carlo Razzeto

Richard A. Lowe said:
#1: Unsafe blocks are still managed by the runtime so memory allocated in
normal .NET ways (i.e. using class constructors and not using the Marshal
class to get a pointer to a chunk of unmanaged memory) will still be managed
by the runtime. There is no way to write *unmanaged* code in C# and unsafe
!= unmanaged.

Ah, ok... Perhaps I just didn't read closely enough.
#2 There's no way to bring a method into a namespace, but is it really so
inconvenient to preface a method call with a class or instance name?

I guess it's more personal preference than anything else. I like to make
classes just to solve a particular problem, not to store groups of loosely
related methods... I also think it makes code look a little messier than it
really needs to.. It's just the way I like to code. But I suppose if I must,
I could write up a class.

Carlo
 

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

Top