Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
| Search | Today's Posts | Mark Forums Read
C# 2012/5.0 General Discussion Discussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2012/5.0 General Discussion 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 August 27th, 2013, 08:34 AM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default autoimplemented property - indexer

this program is given in the page 119 , C#4 Wrox Professional C#

snippet:_
Code:
public class Shape
{
public double Width { get; set; }
public double Height { get; set; }
public override string ToString()
{
return String.Format("Width: {0}, Height: {1}", Width, Height);
}
}
public class Rectangle: Shape
{
}
public interface IIndex < out T >
{
T this[int index] { get; }
int Count { get; }
}
public class RectangleCollection: IIndex<Rectangle>
{
private Rectangle[] data = new Rectangle[3]
{
new Rectangle { Height=2, Width=5},
new Rectangle { Height=3, Width=7},
new Rectangle { Height=4.5, Width=2.9}
};
public static RectangleCollection GetRectangles()
{
return new RectangleCollection();
}
public Rectangle this[int index]
{
get
{
if (index < 0 || index > data.Length)
throw new ArgumentOutOfRangeException("index");
return data[index];
}
}
public int Count   // *******************************n.b
{
get
{
return data.Length;
}
}
}
class MPEP
{
static void Main()
{
IIndex<Rectangle> rectangles = RectangleCollection.GetRectangles();
IIndex<Shape> shapes = rectangles;
for (int i = 0; i < shapes.Count; i++)
{
Console.WriteLine(shapes[i]);
}
}
}
My difficulty is :
Can an auto-implemented property contain only the get part --- I mean the set part in these cases are mandatory isn't it ?
 
Old August 27th, 2013, 01:25 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by amigo1 View Post
this program is given in the page 119 , C#4 Wrox Professional C#
My difficulty is :
Can an auto-implemented property contain only the get part --- I mean the set part in these cases are mandatory isn't it ?
Somewhere you want to set the value of the property, but you can do the set accessor with a private access modifier:
Code:
public string Age { get; private set; }
See page 74 of this book.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
amigo1 (August 30th, 2013)
 
Old August 30th, 2013, 09:53 AM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default thank you

Your writing has always been an inspiration
Thank you very much for your reply.
regards
amigo1




Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Property Value Apocolypse2005 Visual Basic 2008 Essentials 0 September 4th, 2009 03:16 PM
chp 01, get[property name] and set[property name] sandeepgreaternoida BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 0 May 12th, 2009 01:12 AM
Help with LockType property dslagle2 BOOK: Excel 2003 VBA Programmer's Reference 0 August 22nd, 2007 12:33 PM
property umeshtheone Beginning VB 6 2 May 18th, 2007 12:37 AM
Get Model Property graveman Pro VB 6 0 March 10th, 2004 12:41 PM





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