Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shared class - not sure why i get this warning

Posted on 2006-11-13
8
Medium Priority
?
228 Views
Last Modified: 2010-04-23
I have this class:

1.
Namespace Uni.Web.Data.UserData
    Public Class UserAccess

        Private Shared _DBType As DataProvider
        Public Shared Property DBType() As DataProvider
            Get
                Return _DBType
            End Get
            Set(ByVal value As DataProvider)
                _DBType = value

            End Set
        End Property


        Public Shared Function GetSystems(ByVal userLogin As String) As ArrayList
           .....
        End Function

    End Class
End Namespace

2. In my aspx page, why do I need to do this??
 U_DAL.Uni.Web.Data.UserData.UserAccess.DBType =  U_DAL.DataProvider.IBM  

****If I do this, I get a warning:
        Dim test As U_DAL.Uni.Web.Data.UserData.UserAccess
       test.DBType = U_DAL.DataProvider.IBM  

This is the warning : Access of shared member through an instance; qualifying expression will not be evaluated

3. I looked at this site and I'm not using "new" so, that should work:
http://msdn2.microsoft.com/en-us/library/y6t76186.aspx


0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17932948
This is better practice to use shared function or property thru instance variable. It is good to use as class member rather than instance member.

So in your case better to use

U_DAL.Uni.Web.Data.UserData.UserAccess.DBType =  U_DAL.DataProvider.IBM

rather than creating a type variable (instance)
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17932987
"This is NOT better practice to use shared function or property thru instance variable"

sorry for confusion
0
 
LVL 7

Author Comment

by:Camillia
ID: 17933064
but the type variable (instance) should still work..right? or is it changed in 2.0?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Expert Comment

by:riyazthad
ID: 17933127
Farzadw,

I think this will make more clear.

http://msdn2.microsoft.com/en-US/library/4hbsxy95.aspx

0
 
LVL 7

Author Comment

by:Camillia
ID: 17933288
it says " 
It is recommended that you do not write code in which you access a shared member through an instance of the class
"

but then in the example, it goes and creates an instance of of "item":
' Create two instances of the class.
    Dim part1 As New Item("keyboard")
    Dim part2 As New Item("monitor")

then calls the shared method : Item.ShareMethod()

0
 
LVL 6

Accepted Solution

by:
riyazthad earned 2000 total points
ID: 17933404
Yes

But last line Item.SharedMethod , we are calling directly method without creating instance of type 'Item'.

But first two lines part1 and part2 are instances, but we are not calling its shared method, but calling instance method 'InstanceMethod', which is NOT shared method.

Item.ShareMethod()

is just calling its shared method.

So first two calling are recommenting
but not last one becos that is shared method.

in other words

part1.SharedMethod()
or
part2.sharedMethod()

are not recommenting.


0
 
LVL 7

Author Comment

by:Camillia
ID: 17933436
ah, now I get it..

Good, i thought i was doing something wrong...

But the name is too long without creating an instance.
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17933445
Yea, Its okay though.

:-)

Thad
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question