473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Properties Get and Set

1) Cant i write a Set without a get

public bool cccc(bool kkk)
{
set
{
If (kkk=true)
{
bool rrr;
hhhhhh
jjjjjj
}
}
}

2) and how do i return the value

can i say in the same above set

get
{
return rrr;
}

Sep 7 '06 #1
3 1384
Hi Madhavi

A property you only can set values to

private string myProp

public string Prop
{
set
{
if(AcceptableValue(value))
myProp = value;
}
}

A property you only can read

private string myProp

public string Prop
{
get
{
return myProp;
}
}
On Thu, 07 Sep 2006 14:20:31 +0200, Madhavi <ma***********@gmail.com
wrote:
1) Cant i write a Set without a get

public bool cccc(bool kkk)
{
set
{
If (kkk=true)
{
bool rrr;
hhhhhh
jjjjjj
}
}
}

2) and how do i return the value

can i say in the same above set

get
{
return rrr;
}


--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 7 '06 #2
1: Yes; just don't write a "get"
2: You don't return anything from a "set". Ever. An assignment is evaluated
as the value being assigned, so even without the setter the following works,
and sets both fields to 5

Marc

using System;
class SomeClass {
private int someField;
public int SomeProperty {
set { someField = value; }
}
}
class Program {
static void Main() {
SomeClass a = new SomeClass(), b = new SomeClass();
a.SomeProperty = b.SomeProperty = 5;
}
}
Sep 7 '06 #3
Madhavi,

You already got the answers from the other guys, but I just want to say that
having write-only property doesn't make any sense and IMHO is a bad design
decision. Use a method instead.
--
Stoitcho Goutsev (100)

"Madhavi" <ma***********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
1) Cant i write a Set without a get

public bool cccc(bool kkk)
{
set
{
If (kkk=true)
{
bool rrr;
hhhhhh
jjjjjj
}
}
}

2) and how do i return the value

can i say in the same above set

get
{
return rrr;
}

Sep 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick Austin | last post by:
I recently had to perform a reinstalltion of Windows XP (my registry seems to have become corrupt). After this completed I had to reinstall all applications since most use the registry for settings,...
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
6
by: JerryP | last post by:
Hello, is there a way to launch the property dialogue for a directory from my c# app ? I would also like to launch the User Account Properties from Active Directory Users and Computers, and the...
3
by: Martin Montgomery | last post by:
I have, for example, a property called myProperty. I would like, when using a property grid to display the property name as "My Property". Is this possible. Is there an attribute etc Thank ...
7
by: Donald Grove | last post by:
Is it possible to retrieve field properties from a table in access2000 using code? I have tried: " dim dbs as dao.database dim tbl as dao.tabledef dim fld as dao.field dim prop as...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
7
by: Anderskj | last post by:
Hi! I am developing a c# application. I have a interface (which can change therefore my problem) If i do like this: List<PropertyInfoproperties = new List<PropertyInfo>();...
0
by: =?Utf-8?B?UmljayBHbG9z?= | last post by:
For some unknown reason (user error?), I cannot get a NameValueCollection to persist in the app.config file. Unlike other settings, I cannot get the String Collection Editor GUI to allow my to...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.