473,406 Members | 2,633 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.

using a class without creating it (probably an easy question for those who know)

D
I was reviewing these vb.net classes which deal with user logins, logouts,
cookies etc etc.

I noticed that in the Page_Load function of a user control the code calls
into another library like so

Call AnotherClassLibrary.AnotherClass.UserLogin(userId)

I do not understand how this code can call this function without first
creating an instance of the AnotherClass.

What is it that I am not understanding?

Thanks

Best Regards.

Nov 21 '05 #1
4 1279

D wrote:
I was reviewing these vb.net classes which deal with user logins, logouts, cookies etc etc.

I noticed that in the Page_Load function of a user control the code calls into another library like so

Call AnotherClassLibrary.AnotherClass.UserLogin(userId)

I do not understand how this code can call this function without first creating an instance of the AnotherClass.

What is it that I am not understanding?


UserLogin is a *Shared* (static in C# speak, and a lot of the docs)
method of AnotherClass.

Shared members belong to the class-as-a-whole, rather than to
individual instances of the class, which is why you don't need an
object to invoke them on. Shared members exist as a way of putting
class-specific functionality logically 'in' a class definition.

For example, consider the Screen class. Instances of this class
represent actual screens, so for example WorkingArea is a non-Shared
(instance) property - it is a property of an actual Screen.

But consider the method FromPoint that takes a Point and returns a
Screen. Given the OO concept of encapsulation, the only sensible place
for this function to be defined is in the Screen class, but it doesn't
make sense for it to be an instance member. So it is defined as a
Shared member:

Public Shared Function FromPoint(ByVal point As Point) As Screen

and is invoked as Screen.FromPoint.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
"D" <Da**@nothing.net> schrieb:
I noticed that in the Page_Load function of a user control the code calls
into another library like so

Call AnotherClassLibrary.AnotherClass.UserLogin(userId)

I do not understand how this code can call this function without first
creating an instance of the AnotherClass.


Add the 'Shared' attribute to the method you want to access without creating
an instance of the class:

\\\
Public Class AnotherClass
Public Shared Sub UserLogin(ByVal UserID As String)
...
End Sub
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
D

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

D wrote:
I was reviewing these vb.net classes which deal with user logins,

logouts,
cookies etc etc.

I noticed that in the Page_Load function of a user control the code

calls
into another library like so

Call AnotherClassLibrary.AnotherClass.UserLogin(userId)

I do not understand how this code can call this function without

first
creating an instance of the AnotherClass.

What is it that I am not understanding?


UserLogin is a *Shared* (static in C# speak, and a lot of the docs)
method of AnotherClass.

Shared members belong to the class-as-a-whole, rather than to
individual instances of the class, which is why you don't need an
object to invoke them on. Shared members exist as a way of putting
class-specific functionality logically 'in' a class definition.

For example, consider the Screen class. Instances of this class
represent actual screens, so for example WorkingArea is a non-Shared
(instance) property - it is a property of an actual Screen.

But consider the method FromPoint that takes a Point and returns a
Screen. Given the OO concept of encapsulation, the only sensible place
for this function to be defined is in the Screen class, but it doesn't
make sense for it to be an instance member. So it is defined as a
Shared member:

Public Shared Function FromPoint(ByVal point As Point) As Screen

and is invoked as Screen.FromPoint.

--
Larry Lard
Replies to group please


oh ok. I saw that shared word but I was thinking it was like a global or
public access type of thing.

Thanks
Nov 21 '05 #4
D

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ob*************@TK2MSFTNGP10.phx.gbl...
"D" <Da**@nothing.net> schrieb:
I noticed that in the Page_Load function of a user control the code calls
into another library like so

Call AnotherClassLibrary.AnotherClass.UserLogin(userId)

I do not understand how this code can call this function without first
creating an instance of the AnotherClass.


Add the 'Shared' attribute to the method you want to access without
creating an instance of the class:

\\\
Public Class AnotherClass
Public Shared Sub UserLogin(ByVal UserID As String)
...
End Sub
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Ok I get it. thanks alot !!

Nov 21 '05 #5

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

Similar topics

6
by: Jon Slaughter | last post by:
Is there any way to get the class type from a pointer? I'm working on a class that acts as a set: I have two classes, one called FSet and the other called Element. FSet inherets Element and...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
13
by: Bijoy Naick | last post by:
My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions. Instead of copying each helper function into each aspx page, I am thinking of...
11
by: Brent Ritchie | last post by:
Hello all, I have been using C# in my programming class and I have grown quite fond of C# properties. Having a method act like a variable that I can control access to is really something. As...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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...
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
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.