Solved

Shared class - not sure why i get this warning

Posted on 2006-11-13
8
198 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

772 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