I notice that the Dataset designer generates code for properties that
look like this:
public string ID {
get {
try {
return ((string)
(this[this.tablePerso ns.IDColumn]));
}
catch (System.Invalid CastException e) {
throw new System.Data.Str ongTypingExcept ion("The
value for column \'ID\' in table \'Persons\' is DBNull.", e);
}
}
set {
this[this.tablePerso ns.IDColumn] = value;
}
}
In "set", the keyword "this" is used. This is the first time I've
notice it used like this. It seems to act like an indexer but where is
the data stored that it is referring to? 5 1496
this has an indexer on columns which can be accessed by a datacolumn instead
of an int for an index or a string for column name. this.tableperso ns is
the parenttable that knows about all the datacolumns. Having the
tablepersonsdat arow access it's column data in this manner ensures that the
schema is enforced in the entire table, as this would cause a compile error
before execution if the datacolumn was not defined in the datatable.
this[] <-- accesses it's data via datacolumn
this.tablePerso ns.IDColumn <-- datacolumn defiened in the parent table
object to hold the ID for the current personrow.
"Polaris431 " <jo*********@gm ail.comwrote in message
news:11******** **************@ y42g2000hsy.goo glegroups.com.. .
>I notice that the Dataset designer generates code for properties that
look like this:
public string ID {
get {
try {
return ((string)
(this[this.tablePerso ns.IDColumn]));
}
catch (System.Invalid CastException e) {
throw new System.Data.Str ongTypingExcept ion("The
value for column \'ID\' in table \'Persons\' is DBNull.", e);
}
}
set {
this[this.tablePerso ns.IDColumn] = value;
}
}
In "set", the keyword "this" is used. This is the first time I've
notice it used like this. It seems to act like an indexer but where is
the data stored that it is referring to?
You wrote:
this[] <-- accesses it's data via datacolumn
How do you know that it is the datacolumn? Is there some default
property? The class is inherited from a DataRow. Are you saying that
because of this inheritance, the base default property is the
datacolumn you are showing above?
On Sep 25, 7:09 am, Polaris431 <johannbl...@gm ail.comwrote:
You wrote:
this[] <-- accesses it's data via datacolumn
How do you know that it is the datacolumn? Is there some default
property? The class is inherited from a DataRow. Are you saying that
because of this inheritance, the base default property is the
datacolumn you are showing above?
The System.Data.Dat aRow class has several (six, to be exact) overloads
of its indexer. One of them takes a DataColumn:
public object this[DataColumn column]
{
get
{
this.CheckColum n(column);
int defaultRecord = this.GetDefault Record();
return column[defaultRecord];
}
set
...
}
}
(I got this from Reflector, but MSDN also lists the indexers, under
the "Item" property)
Since your typed DataRow derives from System.Data.Dat aRow, you have
those indexers available to use.
Michael mp*******@gmail .com wrote:
[...]
(I got this from Reflector, but MSDN also lists the indexers, under
the "Item" property)
Since your typed DataRow derives from System.Data.Dat aRow, you have
those indexers available to use.
And just to be clear: the "this" keyword is isn't particular to the use
of the indexers. It's just that the syntax in that case requires _some_
identifier to apply the indexer syntax to (ie "[]").
The "this" keyword "works" in this context the same as it does in any
other context. It's just that it's basically required here, where in
most other situations it's not.
Pete
"Peter Duniho" <Np*********@Nn OwSlPiAnMk.comw rote in message
news:13******** *****@corp.supe rnews.com...
mp*******@gmail .com wrote:
>[...] (I got this from Reflector, but MSDN also lists the indexers, under the "Item" property)
Since your typed DataRow derives from System.Data.Dat aRow, you have those indexers available to use.
And just to be clear: the "this" keyword is isn't particular to the use of
the indexers. It's just that the syntax in that case requires _some_
identifier to apply the indexer syntax to (ie "[]").
The "this" keyword "works" in this context the same as it does in any
other context. It's just that it's basically required here, where in most
other situations it's not.
To illustrate Peter's point:
DataRow r = this;
r[column]
works exactly the same as
this[column]
>
Pete
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark Bruno |
last post by:
I thought system("PAUSE"); was part of stdlib.h and cstdlib. Then why does
this work? :
#include <iostream>
using namespace std;
int main()
{
cout << "hello, world" << endl;
system("PAUSE");
return 0;
|
by: Bamber |
last post by:
Why does f get returned ? (compiled with gcc).
#include<stdio.h>
int func(int a);
main()
{ int f;
f=func(7);
printf("f=%d",f);
|
by: cmay |
last post by:
I was suprised to see that you can put a DataTable into viewstate on a
page.
Why does this work? I had understood that the DataTable was in
serializable, which I thought was a requirement of being stored in the
viewstate.
|
by: william |
last post by:
You guys are a great resource for learners such as I. I have seen the way
that you go over and above in explaining even the most mudane things to
beginners, and I think it is a great thing that you do here. I only hope
that you can help me understand how a certain type of application works.
I loaded an app that filters out spam (as it puts it) "before it hits your
inbox".
Now, how does this work? It changed my incoming and outgoing...
|
by: Robert Smith |
last post by:
Why/How does this work?
I know that if I want to convert a signed byte (ie 0x7F) to unsigned
number I can promote it to an integer, like this:
byte a = (byte)0xAB; // -85
int b = a & 0xFF; // 171
The bit pattern is 10101011 (0xAB)
If I AND it with 11111111 (0xFF)
| |
by: Gagan |
last post by:
Hi All,
I am new to VB.NET, and am confused by following code. The code
basically obtains an instance of an object from a helper method. This
helper method instantiates a new object, and returns it. But in its
Finally block, it sets the returned object to Nothing. What perplexes
me is that caller receives a valid object instance.
The queston is: does this work because I am lucky, or this is really
an expected behavior? Also, is this a...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |