Learning C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vicmann

    Learning C#

    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#?

    2. Is this wrong?
    int *p;
    *p = 5; // p is never initialized and could point to anywhere

    3. How to pass p as a pointer into a function?

    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?

    5. In 4, should it say that there are three types for variables in C#:
    value, reference, and pointer?

    Thanks for your help!




  • Peter Duniho

    #2
    Re: Learning C#

    "vicmann" <vicmann@hotmai l.comwrote in message
    news:ua7wsTk%23 GHA.4712@TK2MSF TNGP03.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


    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Learning C#

      Vicman,

      Is this for a palm computer or something like that (from that age as well).

      On my computer are at the moment almost 500 threads runing waiting on
      events, one extra will not harm that in my idea,

      Cor

      "vicmann" <vicmann@hotmai l.comschreef in bericht
      news:ua7wsTk%23 GHA.4712@TK2MSF TNGP03.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#?
      >
      2. Is this wrong?
      int *p;
      *p = 5; // p is never initialized and could point to anywhere
      >
      3. How to pass p as a pointer into a function?
      >
      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?
      >
      5. In 4, should it say that there are three types for variables in C#:
      value, reference, and pointer?
      >
      Thanks for your help!
      >
      >
      >
      >

      Comment

      • chanmm

        #4
        Re: Learning C#

        Put * in C# :-). I still say look at the C# specification, there are plenty
        good details in there.


        chanmm

        "vicmann" <vicmann@hotmai l.comwrote in message
        news:ua7wsTk%23 GHA.4712@TK2MSF TNGP03.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#?
        >
        2. Is this wrong?
        int *p;
        *p = 5; // p is never initialized and could point to anywhere
        >
        3. How to pass p as a pointer into a function?
        >
        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?
        >
        5. In 4, should it say that there are three types for variables in C#:
        value, reference, and pointer?
        >
        Thanks for your help!
        >
        >
        >
        >

        Comment

        Working...