C# Questions

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

    #1

    C# Questions

    Hi everybody.

    I am new to C#, I come from a VB 6 background, so there are some pretty big
    difference that I need to get used to, so please bear with me if my
    questions are simple.

    1. In my C# application, I use a monthCalendar. What I basically want is
    when I click a day in the week, it must highlight that whole week for me
    automatically. Now I managed to get to pass the date that was selected by
    the user, but what I want to do is determine the date of the first day in
    that week. i.e. if I select the 06/11/2003(Thursday), and my first day of
    the week is Monday, then I want my method to figure out the date of Monday
    and set the monthCalendars start and end date from Mondays date - Sundays
    date. I do not know how to do this. I see that the DateTime class has
    AddDays,AddMont hs etc, but I do not see anything for SubtractDays or
    SubtractMonths etc. I do see that there is a Subtract method, but I can only
    get it to work if I already know what Mondays date is! Any help would be
    SOOOO appreciated.

    2. I know that in VB6, if I ran my app, and there was an error in the code,
    I could pause the app, fix the problem, or even add in extra lines of code,
    and carry on executing, however in my C# app, when there is a problem, or I
    come to a breakpoint, and I want to change something, or add new lines of
    code, it asks me whether I want to restart, or continue, If I restart, the
    app closes down and is re-run, if I choose continue, the app carries on, but
    ignores my changes or additions. Am I doing something wrong? Why do I need
    to restart the whole app for my changes to take effect. Again, any info is
    greatly appreciated

    TIA for your help

    Kevin


  • Jon Skeet [C# MVP]

    #2
    Re: C# Questions

    Kevin <kevinpotgieter @absamail.co.za > wrote:[color=blue]
    > I am new to C#, I come from a VB 6 background, so there are some pretty big
    > difference that I need to get used to, so please bear with me if my
    > questions are simple.
    >
    > 1. In my C# application, I use a monthCalendar. What I basically want is
    > when I click a day in the week, it must highlight that whole week for me
    > automatically. Now I managed to get to pass the date that was selected by
    > the user, but what I want to do is determine the date of the first day in
    > that week. i.e. if I select the 06/11/2003(Thursday), and my first day of
    > the week is Monday, then I want my method to figure out the date of Monday
    > and set the monthCalendars start and end date from Mondays date - Sundays
    > date. I do not know how to do this. I see that the DateTime class has
    > AddDays,AddMont hs etc, but I do not see anything for SubtractDays or
    > SubtractMonths etc. I do see that there is a Subtract method, but I can only
    > get it to work if I already know what Mondays date is! Any help would be
    > SOOOO appreciated.[/color]

    To subtract days, just call AddDays with a negative value.
    [color=blue]
    > 2. I know that in VB6, if I ran my app, and there was an error in the code,
    > I could pause the app, fix the problem, or even add in extra lines of code,
    > and carry on executing, however in my C# app, when there is a problem, or I
    > come to a breakpoint, and I want to change something, or add new lines of
    > code, it asks me whether I want to restart, or continue, If I restart, the
    > app closes down and is re-run, if I choose continue, the app carries on, but
    > ignores my changes or additions. Am I doing something wrong? Why do I need
    > to restart the whole app for my changes to take effect. Again, any info is
    > greatly appreciated[/color]

    There's no edit-and-continue in either VB.NET or C#, although there
    will be in VB.NET in the next version of Visual Studio .NET. As for why
    this is - there's an awful lot going on under the covers, and changing
    code in the middle of execution is not a simple task by any means.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Daniel Pratt

      #3
      Re: C# Questions

      Hi Kevin,

      "Kevin" <kevinpotgieter @absamail.co.za > wrote in message
      news:O5%23EYSIp DHA.1740@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Hi everybody.
      >
      > I am new to C#, I come from a VB 6 background, so there are some pretty[/color]
      big[color=blue]
      > difference that I need to get used to, so please bear with me if my
      > questions are simple.
      >
      > 1. In my C# application, I use a monthCalendar. What I basically want is
      > when I click a day in the week, it must highlight that whole week for me
      > automatically. Now I managed to get to pass the date that was selected by
      > the user, but what I want to do is determine the date of the first day in
      > that week. i.e. if I select the 06/11/2003(Thursday), and my first day of
      > the week is Monday, then I want my method to figure out the date of Monday
      > and set the monthCalendars start and end date from Mondays date - Sundays
      > date. I do not know how to do this. I see that the DateTime class has
      > AddDays,AddMont hs etc, but I do not see anything for SubtractDays or
      > SubtractMonths etc. I do see that there is a Subtract method, but I can[/color]
      only[color=blue]
      > get it to work if I already know what Mondays date is! Any help would be
      > SOOOO appreciated.[/color]

      Here's an example:

      DateTime dateNow = DateTime.Now;
      DateTime dateMonday = dateNow.AddDays (DayOfWeek.Mond ay -
      dateNow.DayOfWe ek);

      Console.WriteLi ne("Monday's date: {0}", dateMonday);

      If dateNow is the date of a day in a certain week, then dateMonday is
      the date of Monday in that week. If you wanted Sunday to be treated as the
      last day of the week, you'd have to finagle this a bit, but you get the
      idea.
      [color=blue]
      > 2. I know that in VB6, if I ran my app, and there was an error in the[/color]
      code,[color=blue]
      > I could pause the app, fix the problem, or even add in extra lines of[/color]
      code,[color=blue]
      > and carry on executing, however in my C# app, when there is a problem, or[/color]
      I[color=blue]
      > come to a breakpoint, and I want to change something, or add new lines of
      > code, it asks me whether I want to restart, or continue, If I restart, the
      > app closes down and is re-run, if I choose continue, the app carries on,[/color]
      but[color=blue]
      > ignores my changes or additions. Am I doing something wrong? Why do I need
      > to restart the whole app for my changes to take effect. Again, any info is
      > greatly appreciated[/color]

      You are not doing something wrong. "Edit and Continue", as it is called,
      is not a feature of any .NET language including VB.NET. I believe E & C
      will be supported for VB.NET only in .NET 2.0 (due sometime in the latter
      part of 2004).

      Regards,
      Dan


      Comment

      Working...