Click here to Skip to main content
14,928,740 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using generics without the caller knowing what type to expect Pin
Jörgen Andersson1-Oct-14 21:14
professionalJörgen Andersson1-Oct-14 21:14 
GeneralRe: Using generics without the caller knowing what type to expect Pin
PIEBALDconsult1-Oct-14 9:41
professionalPIEBALDconsult1-Oct-14 9:41 
GeneralRe: Using generics without the caller knowing what type to expect Pin
Jörgen Andersson1-Oct-14 21:30
professionalJörgen Andersson1-Oct-14 21:30 
AnswerRe: Using generics without the caller knowing what type to expect Pin
Pete O'Hanlon1-Oct-14 21:23
mvePete O'Hanlon1-Oct-14 21:23 
GeneralRe: Using generics without the caller knowing what type to expect Pin
Jörgen Andersson1-Oct-14 21:35
professionalJörgen Andersson1-Oct-14 21:35 
AnswerRe: Using generics without the caller knowing what type to expect Pin
jschell3-Oct-14 9:20
Memberjschell3-Oct-14 9:20 
AnswerRe: Using generics without the caller knowing what type to expect Pin
aljodav3-Oct-14 18:22
Memberaljodav3-Oct-14 18:22 
QuestionUsing protected set accessor Pin
robwm11-Oct-14 6:23
Memberrobwm11-Oct-14 6:23 
Hi,

I'm working on a course for 98-361 Software Development Fundamentals. I am given the following example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Lesson02
{
    
    abstract class Polygon
    {
        public double Length {get; protected set;}
        public double Width {get; protected set;}
        abstract public double GetArea();
    }
    
    class Rectangle: Polygon
    {
        public Rectangle(double length, double width)
        {
            Length = length;
            Width = width;
        }

        public override double GetArea()
        {
            return Width * Length;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle(10, 20);
            Console.WriteLine(
                "Width={0}, Length={1}, Area = {2}",
                rect.Width, rect.Length, rect.GetArea());
        }

    }
}


Here is a paragraph from the text that I am struggling with:

The properties Length and Width in the Polygon class are declared with a protected access modifier for the set accessor. This means that access to the set accessor is available only inside the Polygon class and its derived classes. You can still get the value of the Length and Width properties in the Main method, but you’ll get an error if you attempt to assign a value to these properties.

What I would like to know is to see code that shows how to use the set accessor properly and what does it look like if you try to assign a value from Main. I understand it will fail but I'd like to see it for myself. I am new to C# and unsure of how to introduce the code myself for an accurate demo.

Unfortunately, my instructors apparently don't write code so they are unable to answer my question.

Thank you!
Rob

modified 1-Oct-14 12:32pm.

AnswerRe: Using protected set accessor Pin
BillWoodruff1-Oct-14 7:00
mveBillWoodruff1-Oct-14 7:00 
GeneralRe: Using protected set accessor Pin
robwm11-Oct-14 7:17
Memberrobwm11-Oct-14 7:17 
AnswerRe: Using protected set accessor Pin
Richard Deeming1-Oct-14 7:01
mveRichard Deeming1-Oct-14 7:01 
GeneralRe: Using protected set accessor Pin
robwm11-Oct-14 7:14
Memberrobwm11-Oct-14 7:14 
GeneralRe: Using protected set accessor Pin
Richard Deeming1-Oct-14 7:32
mveRichard Deeming1-Oct-14 7:32 
GeneralRe: Using protected set accessor Pin
robwm11-Oct-14 7:36
Memberrobwm11-Oct-14 7:36 
GeneralRe: Using protected set accessor Pin
Andy_L_J1-Oct-14 22:12
MemberAndy_L_J1-Oct-14 22:12 
GeneralRe: Using protected set accessor Pin
robwm12-Oct-14 5:00
Memberrobwm12-Oct-14 5:00 
Questionmultiple / change report in one report viewer Pin
just1c3ss1-Oct-14 1:14
Memberjust1c3ss1-Oct-14 1:14 
AnswerRe: multiple / change report in one report viewer Pin
ZurdoDev1-Oct-14 1:38
professionalZurdoDev1-Oct-14 1:38 
QuestionPass a value from different project Pin
Member 1102592430-Sep-14 17:42
MemberMember 1102592430-Sep-14 17:42 
AnswerRe: Pass a value from different project Pin
V.30-Sep-14 19:40
professionalV.30-Sep-14 19:40 
AnswerRe: Pass a value from different project Pin
BillWoodruff30-Sep-14 21:24
mveBillWoodruff30-Sep-14 21:24 
GeneralRe: Pass a value from different project Pin
Member 1102592430-Sep-14 21:26
MemberMember 1102592430-Sep-14 21:26 
GeneralRe: Pass a value from different project Pin
BillWoodruff30-Sep-14 23:25
mveBillWoodruff30-Sep-14 23:25 
QuestionRe: Pass a value from different project Pin
Kornfeld Eliyahu Peter30-Sep-14 22:01
professionalKornfeld Eliyahu Peter30-Sep-14 22:01 
AnswerRe: Pass a value from different project Pin
Member 1102592430-Sep-14 22:03
MemberMember 1102592430-Sep-14 22:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.