Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 July 28th, 2006, 07:55 AM
Authorized User
Join Date: May 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default What does this("Default Name") mean?

I am reading Begining Visual C# 2005. I encounted a question about the following part. Anyone help me out? see the comments!

using System;
using System.Collections.Generic;
using System.Text;

namespace Ch10Ex01
    class MyClass
        public readonly string Name;
        private int intVal;

        public int Val
            get { return intVal; }
                if (0 <= value && value <= 10)
                    intVal = value;
                    throw (new ArgumentOutOfRangeException("Val", value,
                        "Val must be assigned a value between 0 and 10."));
        public override string ToString()
            return "Name: " + Name + "\nVal: " + Val;
        private MyClass()
            : this("Default Name") /*Explaination in the book:Note that I've used this("Default Name") to ensure that Name gets a value if this constructor ever gets called, which is possible if this class is used to derive a new class. This is necessary as not assigning a value to the Name field could be a source of errors later.*/

/* What's puzzling me: How can it be used in a derived class as it's "private"? What does this("Default Name") mean? How does the object get the "Default Name" as its name? */

        public MyClass(string newName)
            Name = newName;
            intVal = 0;

Similar Threads
Thread Thread Starter Forum Replies Last Post
no default value for drop down nasirmunir HTML Code Clinic 3 June 10th, 2008 01:13 PM
default ambrosejp SharePoint Admin 2 April 20th, 2006 01:56 PM
how to default an attribute value David Li XSLT 1 February 8th, 2006 09:20 AM
default browser dwz VB How-To 1 November 10th, 2003 08:55 AM

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