"vicmann" <vi*****@hotmail.comwrote in message
news:ua****************@TK2MSFTNGP03.phx.gbl...
1. Put an application in sleep mode so that it consumes as little PC
resource as possible. When triggered by an event, back to normal/work
mode.
After done with work, back to sleep mode again.
How can this be done in C#?
In essentially the same way it would be done using the native Windows API.
The exact method depends on what "event" you mean, but the simplest example
would be to create a waitable event, use the Wait method on it, and
somewhere else use the Set method on the event to signal it and allow the
code sitting at the Wait method to continue.
2. Is this wrong?
int *p;
*p = 5; // p is never initialized and could point to anywhere
You can't even do that in C# without writing "unsafe" code. However, given
that assumption, yes...just as in C it's wrong to dereference an
uninitialized pointer, so too it is in C#.
3. How to pass p as a pointer into a function?
Again, without writing "unsafe" code, you don't. C# does however have a
"ref" keyword that allows passing things by reference.
4. "C# is a type-safe language. Variables are declared as being of a
particular type, and each variable is constrained to hold only values of
its
declared type." What's the exact meaning of "type-safe" here?
I would say "Variables are declared as being of a particular type, and each
variable is constrained to hold only values of its declared type" covers it
pretty well.
5. In 4, should it say that there are three types for variables in C#:
value, reference, and pointer?
No, not really. IMHO the "unsafe" construct is mostly a non-C# thing. That
is, it's a way to write non-C# code within C#. It reminds me a lot of using
the "__asm" keyword in C. With "real" C# code, all you have are values or
references.
Additionally, the kinds of variables don't really have anything to do with
being type-safe. That is, type-safe refers to the type checking when
variables are used. How those variables are stored doesn't relate to how
types are checked. So, no...I wouldn't expect a description of "type-safe"
to necessarily mention the kinds of variables that the language supports.
Pete