Why set null before initializing an object in C #

I follow the guide on using video capture using the Windows MediaCapture API on Windows Phone and with code examples, some of the variables are set to zero before assigning a new instance.

private void InitCaptureSettings() {
    _captureInitSettings = null;
    _captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
    _captureInitSettings.AudioDeviceId = "";
    _captureInitSettings.VideoDeviceId = "";
    _captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
    _captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;

    if (_deviceList.Count > 0) {
        _captureInitSettings.VideoDeviceId = _deviceList[0].Id;
    }
}

Is there a reason why this should be done?

thank

+4
source share
3 answers

, MediaCaptureInitializationSettings , , "" . , . ( , , ...)

:

_captureInitSettings = new MediaCaptureInitializationSettings
{
    AudioDeviceId = "",
    VideoDeviceId = _deviceList.Count > 0 ? _deviceList[0].Id : "",
    StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
    PhotoCaptureSource = PhotoCaptureSource.VideoPreview
};

:

  • , IMO...
  • , . , .
+9

.

?

" ".

-: , , , . - , .. , .

+1

, .

, MediaCaptureInitializationSettings NULL, MediaCaptureInitializationSettings.

A variable set to NULL does not affect the new instance.

0
source

All Articles