こんにちは私は、VBでByrefとByValを使って何かをしようとしています。メソッドを通してオブジェクトを渡しています。オブジェクトの値ですが、私は明確ではありません誰も私はこの2つの概念をはっきりと理解するのを助けることができますしてください。下は私がarr Listの値を変更しようとしているメソッドですが、列挙操作が実行されないことがあります.BevalとByrefのこのロジックを理解するのを助けてください。値渡し、参照渡し、汎用リストのオブジェクトの値の変更VB
Public Function arrayReturn() As List(Of Object)
Dim arr As List(Of Object)
arr = New List(Of Object)
For index As Integer = 1 To 5
arr.Add(index)
Debug.Write(index.ToString & " ")
Next
For Each i As Object In arr
arr.Add(intReturn(i))
Next
Return arr
End Function
Public Function intReturn(ByRef i As Object) As Integer
i += i
Return i
End Function
Sub Main()
Dim obj As List(Of Object)
obj = New List(Of Object)
obj = arrayReturn()
For Each obj2 As Object In obj
Console.WriteLine(obj2)
Next
End Sub
私の問題は、私はイベントオブジェクトをretriveしようとするとイベントのリストにそれを入れています、ここでこの方法を使用することですが、私はそうここ
Public Function GetIcalForAppointments(nxtMonth As Integer, prevMonth As Integer, strStaffAPIKey As String) As Ical.NET.Calendar
Dim objDTOIcallApt As DTOICallAppt
objDTOIcallApt = New DTOICallAppt
Dim lst As List(Of DOAppointment)
objDTOIcallApt = GetAllAppointmentsForIcal(nxtMonth, prevMonth, strStaffAPIKey)
lst = objDTOIcallApt.Appointments
Dim timeZoneName As String = objDTOIcallApt.UserTimezone
Dim calendar As Ical.NET.Calendar
calendar = New Ical.NET.Calendar()
Dim timeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName)
calendar.AddTimeZone(New Ical.NET.VTimeZone(timeZoneName))
Dim evt As Ical.NET.Event
For Each appt As DOAppointment In lst
GetIcalForAppointment(appt, objDTOIcallApt, calendar, evt)
Next
Return calendar
End Function
Public Function GetIcalForAppointment(app As DOAppointment, objResponse As DTOICallAppt, calendar As Ical.NET.Calendar, ByRef evt As Ical.NET.Event) As Ical.NET.Event
evt = calendar.Create(Of Ical.NET.Event)()
evt.Start = getCalDateTime(app.StartDate, calendar)
evt.End = getCalDateTime(app.EndDate, calendar)
evt.Description = app.FullSubject
evt.Location = app.AppointmentInOrgName
evt.IsAllDay = False
evt.Created = getCalDateTime(app.CreatedDatetime, calendar)
If objResponse.UserEmail <> "" AndAlso objResponse.UserEmail.Contains("@") = True Then
evt.Organizer = New Organizer("MAILTO:" + objResponse.UserEmail)
End If
Select Case app.AppointmentStatus
Case "Cancelled"
evt.Status = Ical.NET.EventStatus.Cancelled
Exit Select
Case "NoShow"
evt.Status = Ical.NET.EventStatus.Cancelled
Exit Select
Case "Scheduled"
evt.Status = Ical.NET.EventStatus.Tentative
Exit Select
Case Else
evt.Status = Ical.NET.EventStatus.Confirmed
Exit Select
End Select
evt.Categories.Add("Work")
evt.Comments.Add(app.CreatedDetails)
evt.Resources.Add(app.Resource1Name)
evt.Resources.Add(app.Resource2Name)
Dim strSummary As String = app.FullSubject
If app.IsPatConsentRequired = True Then
If app.IsPatConsentGiven = True Then
strSummary = strSummary & Convert.ToString(" | Consent given")
Else
strSummary = strSummary & Convert.ToString(" | Consent Pending")
End If
End If
If app.PatMedicalHistoryCasesheetID <> "" Then
If app.IsMedicalHistoryFilled = True Then
strSummary = strSummary & Convert.ToString(" | Medical History filled")
Else
strSummary = strSummary & Convert.ToString(" | Medical History pending")
End If
End If
evt.Summary = strSummary
evt.Uid = app.ID
Dim alarm As New Ical.NET.Alarm
alarm.Action = Ical.NET.AlarmAction.Display
alarm.Summary = "Appointment with " + app.AppointmentWithFullName + " at " + app.AppointmentInOrgName
alarm.Trigger = New Trigger(TimeSpan.FromMinutes(-30))
evt.Alarms.Add(alarm)
Return evt
End Function
を右だかwheter私はなっておりません私は単一のイベントオブジェクトを取得し、毎回イベントリストにプッシュしようとしているのがわかります
2番目のforループでは、既存のものを変更する代わりに新しい要素を追加します。 'arr(i)= intReturn(i)'は動作するはずです。 – Turamarth
と、他の方法ではなくforeachループのためのオブジェクトの取得方法... @ turamarth – Tanmay
唯一の問題が例外であれば、@Turamarthは正しいです。さらに助けが必要な場合は、答えを書き換えて特定の問題を述べるか、問題ごとに複数の質問を書く必要があります。 byrefとbyvalが何であるかを説明するマニュアルが必要な場合は、[こちら](https://msdn.microsoft.com/en-us/library/ee478101(v = vs.84).aspx)は –