Question on inheritance.

T

tshad

I am playing with classes and got the following error:

c:\inetpub\wwwroot\hello\SecureService.asmx(135) : warning BC40004: variable
'Se
ssionKey' conflicts with variable 'SessionKey' in the base class
'AuthHeader' an
d so should be declared 'Shadows'.

Public SessionKey As String
~~~~~~~~~~

Now the Classes I have are:
***************************************
Public Class AuthHeader:Inherits SoapHeader
Public SessionKey As String
End Class

Public Class ServiceTicket:Inherits AuthHeader
Public IsAuthenticated As Boolean
Public SessionKey As String
Public Expiration As DateTime
End Class

Public Class TempClass1:ServiceTicket
Public TomsClass1Name As String
End Class
**************************************

If I comment out the TempClass1, it works fine:
***************************************
Public Class AuthHeader:Inherits SoapHeader
Public SessionKey As String
End Class

Public Class ServiceTicket:Inherits AuthHeader
Public IsAuthenticated As Boolean
Public SessionKey As String
Public Expiration As DateTime
End Class

'Public Class TempClass1:ServiceTicket
' Public TomsClass1Name As String
'End Class
****************************************

Why doesn't the SessionKey in "ServiceTicket", conflict with the SessionKey
in AuthHeader?

Thanks,

Tom
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

This is a C# group, yours is a VB.net question.

your problem is that one of the classes you inherit from declare a
SessionKey variable, so yours collide with the other.
Solution;
Simply rename your variable and use another name.
 
V

Vijay

It does for me even after I comment TempClass1... I am on 1.1 with VS.NET
2003

Vijay
 
T

tshad

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

This is a C# group, yours is a VB.net question.
You're right.

I have been going back and forth between VB.Net and C# and wasn't paying
attention.

I also found the problem was that I was missing the word "Inherits" in the
TempClass1 declaration.

Thanks,

Tom
 
T

tshad

Vijay said:
It does for me even after I comment TempClass1... I am on 1.1 with VS.NET
2003

As I mentioned above, I forgot the Inherits keyword and didn't wasn't paying
attention to language (VB.Net) and the newsgroup.

Thanks,

Tom
 
V

Vijay

I understand.. very similar to you I juggle VB/C# very much...in a given
week

Vijay
 
T

tshad

Yes,

I typically write my Asp.Net code in VB.Net, but I like to use C# to build
my classes because it is really convenient for naming.

I use camel case for my private variables: firstName, lastName.

I then use Pascal Case for my Properties: FirstName, LastName.

Makes it easy to differentiate the variables and I don't need to use
underscores, as others do.

Tom
 
V

Vijay

just curious why do you use VB.NET with ASP.NET?.. isn't C# better to use in
ASP.NET?

Vijay
 
T

tshad

Vijay said:
just curious why do you use VB.NET with ASP.NET?.. isn't C# better to use
in ASP.NET?

Actually, no.

They are essentially the same. I assume there are some disagreements, but
as far as I have read, there really is no real difference between the 2
(other than syntax). I am sure there are some, but I think for most of the
everyday use - this is not the case.

I actually am a C programmer (have been for about 10 years) and decided to
build our site with VB.Net because of the lack of differences and I wanted
to learn something different. This would not have been the case before
VB.Net. I would never have done VB6 instead of C++.

As I mentioned, I do prefer C# for building Classes ( I am not talking about
Asp.Net pages, which are also Classes).

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top