Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
This is the forum to discuss the Wrox book Beginning Microsoft Visual C# 2008 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780470191354
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 28th, 2010, 04:20 AM
Registered User
 
Join Date: Sep 2010
Location: Beira - Mozambique
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Breakpoint in Ch09Ex01

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ch09Ex01
{
    public abstract class MyBase
    {
    }

    internal class MyClass : MyBase
    {
    }

    public interface IMyBaseInterface
    {
    }

    internal interface IMyBaseInterface2
    {
    }

    internal interface IMyInterface : IMyBaseInterface, IMyBaseInterface2
    {
    }

    internal sealed class MyComplexClass : MyClass, IMyInterface
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            MyComplexClass myObj = new MyComplexClass();
            Console.WriteLine(myObj.ToString());
            Console.ReadKey();
        }
    }
}
Question 1: When I put a breakpoint (to follow the sequence of the program) on "MyComplexClass myObj...." in class Program, it never jumps to one of the classes and interfaces before the class Program. Why not?
Question 2: I cannot set any breakpoint on one of the classes/interfaces before the class Program. Why not?
Question 3: I cannot put a "Console.WriteLine();" in one of the classes or interfaces. It gives an error on the "(" with the message "Invalid token '(' in class, ....." Why can I not put a Console.WriteLine() between the {} ?

Best regards,
perloc
Reply With Quote
  #2 (permalink)  
Old October 28th, 2010, 06:10 AM
Imar's Avatar
Wrox Author
Points: 67,581, Level: 100
Points: 67,581, Level: 100 Points: 67,581, Level: 100 Points: 67,581, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,269
Thanks: 66
Thanked 1,428 Times in 1,408 Posts
Default

Hi there,

These classes and interfaces are empty and contain no runnable code yet; they are only a class or interface definition. That means you can't set breakpoints as the code will never run, and can thus never cause the debugger to break. So:

Quote:
Question 1: When I put a breakpoint (to follow the sequence of the program) on "MyComplexClass myObj...." in class Program, it never jumps to one of the classes and interfaces before the class Program. Why not?
Because they contain no executable code. Once you add a method (and call that) or a constructor, it'll be called. E.g.:

Code:
internal sealed class MyComplexClass : MyClass, IMyInterface
{
  internal MyComplexClass()
  {
  }
}
If you put a breakpoint on internal MyComplexClass(), it will break.

Quote:
Question 2: I cannot set any breakpoint on one of the classes/interfaces before the class Program. Why not?
Because they contain no executable code.

Quote:
Question 3: I cannot put a "Console.WriteLine();" in one of the classes or interfaces. It gives an error on the "(" with the message "Invalid token '(' in class, ....." Why can I not put a Console.WriteLine() between the {} ?
You can't add executable code such as Console.WriteLine in a class definition directly. You need to add it to a member such as a method, property, constructor and so on. This should work:


Code:
internal sealed class MyComplexClass : MyClass, IMyInterface
{
  internal MyComplexClass()
  {
    Console.WriteLine("Constructor called");
  }
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Viewing user window while paused at breakpoint Winsteps BOOK: Visual Basic 2010 Programmer's Reference 5 June 14th, 2010 08:51 AM
The breakpoint is not been Hit uchkid Pro Visual Basic 2005 1 August 29th, 2006 11:52 AM
Breakpoint not hit - "No symbols loaded for page" organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 15 August 1st, 2006 07:08 PM
Cant hit a breakpoint in report open event badgolfer Access 1 July 5th, 2004 12:08 AM
Breakpoint Error Msg Louisa VB.NET 2002/2003 Basics 1 March 29th, 2004 06:42 AM



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.