[英]how to get properties of an object in a function when it's not in the parameter
I'm not that good at VB yet and I have some serious issues fixing something. 我不太擅长VB,并且在解决某些问题时遇到了一些严重的问题。 For school I have to make a task and I have some test that all have to run True
对于学校,我必须完成一项任务,并且进行一些测试,所有测试都必须运行为True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay2) = False) 'True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay3) = False) 'True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay4) = True) 'True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay5) = True) 'True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay6) = False) 'True
Console.WriteLine(placeToStay1.Overlapswith(placeToStay7) = False) 'True
An example of a placeToStay with the properties: 具有属性的placeToStay的示例:
Dim placeToStay1 As New placeToStay
placeToStay1.Room = 123 'String
placeToStay1.From = #10/23/2013# 'Date
placeToStay1.Till = #10/28/2013# 'Date
This is what I have in my class: 这是我课堂上的内容:
Public Class placeToStay
Public Property Room As String
Public Property From As Date
Public Property Till As Date
Dim _tillDate As Date = Till
Public Function OverlapsWith(date2 As placeToStay) As Boolean
Dim TheBool As Boolean
If _tillDate > date2.From Then
TheBool = True
Else
TheBool = False
End If
Console.WriteLine(_tillDate)
Return TheBool
End Function
End Class
As you might have guessed this doesn't return true at all. 您可能已经猜到这根本不返回true。 How can I get the Till property from placeToStay1 if it's not given in a parameter?
如果未在参数中给定,如何从placeToStay1获取Till属性 ?
The testcode must remain unchanged (the console.writeline lines) Any help is welcome :) 测试代码必须保持不变(console.writeline行),欢迎任何帮助:)
I assume two instances "overlap" if the From/Till date of one, falls within the From/Till date of the other? 我假设两个实例“重叠”,如果其中一个的起始/终止日期落在另一个的起始/终止日期之内?
If yes, then try something like: 如果是,请尝试以下操作:
Public Class placeToStay
Public Property Room As String
Public Property From As Date
Public Property Till As Date
Public Function OverlapsWith(ByVal pts As placeToStay) As Boolean
Return (pts.From >= Me.From AndAlso pts.From <= Me.Till) OrElse
(pts.Till >= Me.From AndAlso pts.Till <= Me.Till)
End Function
End Class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.