Solved

Shared class - not sure why i get this warning

Posted on 2006-11-13
8
182 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now