C# Questions

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

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,AddMonths 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
 
Kevin said:
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,AddMonths 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.

To subtract days, just call AddDays with a negative value.
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

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.
 
Hi Kevin,

Kevin said:
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,AddMonths 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.

Here's an example:

DateTime dateNow = DateTime.Now;
DateTime dateMonday = dateNow.AddDays(DayOfWeek.Monday -
dateNow.DayOfWeek);

Console.WriteLine("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.
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

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
 
Back
Top