473,406 Members | 2,769 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,406 software developers and data experts.

get() & set() property

6
Hi,

Can you explain with code the get() & set() property in VB.Net.
Thanks,
Pratip
Oct 18 '06 #1
2 16053
Public Class Hello
Private _sample As String
Public Property Sample() As String
Get
'1
Return _sample
End Get
Set(ByVal Value As String)
'2
_sample = Value
End Set
End Property

Public Sub DoSomething()
Me.Sample = "SampleText" '2
MessageBox.Show(Me.Sample) '1
End Sub
End Class
Oct 18 '06 #2
bharathreddy
111 100+
We know that data encapsulation and hiding are the two fundamental characteristics of any object oriented programming language. We create private variables/members in a class. In order to set and get the values in these variables we use public functions normally. In addition to that C# provides a built in mechanism called properties using these we can set and get the values of the private member variables.

Syntax of Properties:

<acces_modifier> <return_type> <property_name>
{
get
{
}
set
{
}
}


Example :

class MyClass
{
private int x; //Private variable
public int X //Property used to set and get the values of x.
{
get
{
return x;
}
set
{
x = value;
}
}
}
class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
mc.X = 10;
int xVal = mc.X;
Console.WriteLine(xVal);//Displays 10
}
}

Thanks & Regs
Bharath Reddy Vasireddy
India
Oct 19 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
4
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image...
0
by: Zeng | last post by:
I wish the Get & Set methods for a property are separate in C#. It would be nice if I could do the following: class Base { public bool IsFoo { set { m_isFoo = value; } }
3
by: Doug | last post by:
Does anyone know of a way that you can use System.Reflection.MethodInfo to get a list of methods within a class and NOT have it show the Get and Set methods of properties?
4
by: Sadun Sevingen | last post by:
i have SqlParameterCollection and i want to reach it by SET and GET methods... public SqlParameterCollection Parameter this { get { return Command.Parameters; } set
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
0
by: Cordine | last post by:
i've got a class, with a public property cName (string). i've instantiated the class, & when i try to execute the following piece of coding, Me.TextName.DataBindings.Add(New Binding("Text",...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
7
by: =?Utf-8?B?U2NhbmJveQ==?= | last post by:
Guyz, I have just learnt how to add the 'DriveListBox', 'DirListBox' and 'FileListBox' controls that were always included in the toolbox with VB 3.0 / 4.0 / 5.0, but always missing in VBE 2005....
8
Fary4u
by: Fary4u | last post by:
Hi any body tell me where is the problem ? i'm trying 2 search but desnt' come with nothing plz help me in this regards chkres = Request.form("chkres") chkcom = Request.form("chkcom")...
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.