Structures and Objects

  • Thread starter Thread starter sougata12
  • Start date Start date
S

sougata12

Guest
Hi,

I am trying to define an object as a field for the structure. But getting an error..Can I get some help pls?

Public Class car
Public Property make As String
Public Property miles As Integer
End Class

Public Structure employee
Public name As String
Public reporting_authority As String
Public c1 As car
End Structure

Module Module1

Sub Main()
Dim e As employee
e.name = "Sougata" : e.reporting_authority = "Jaideep"
e.c1.make = "Ford" : e.c1.miles = 123456
Console.WriteLine($"Name: {e.name}")
Console.WriteLine($"Reports to: {e.reporting_authority}")
Console.WriteLine($"Owns a {e.c1.make} car")
Console.WriteLine($"Distance: {e.c1.make}")
Console.ReadLine()
End Sub

End Module

The error I ma getting is:

1371487.png

Pls tell me where I am going wrong. Also, apart from the error, can someone explain why the green squiggly line is appearing only under "e.c1.make" and not "e.c1.miles"? If what I have done is wrong, Should it not appear under both?


Sougata Ghosh

Continue reading...
 
Back
Top