Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2010, 03:20 AM
Registered User
 
Join Date: Sep 2010
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
 
Old October 28th, 2010, 05:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!





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 07:51 AM
The breakpoint is not been Hit uchkid Pro Visual Basic 2005 1 August 29th, 2006 10:52 AM
Breakpoint not hit - "No symbols loaded for page" organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 15 August 1st, 2006 06:08 PM
Cant hit a breakpoint in report open event badgolfer Access 1 July 4th, 2004 11:08 PM
Breakpoint Error Msg Louisa VB.NET 2002/2003 Basics 1 March 29th, 2004 06:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.