Reputation: 107
This is my code:
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
namespace andyify
{
internal class CommonOpenFileDialog
{
internal readonly string FileName;
public string IntialDirectory { get; internal set; }
public bool IsFolderPicker { get; internal set; }
internal CommonFileDialogResult ShowDialog()
{
}
}
}
And I am getting this error:
Error CS0161
'CommonOpenFileDialog.ShowDialog()': not all code paths return a value.
Does anyone know why this is? Can someone please help me? Thank you
Upvotes: 0
Views: 394
Reputation: 81493
You are receiving the following error Compiler Error CS0161
not all code paths return a value
A method that returns a value must have a return statement in all code paths. For more information, see Methods.
Further more
Methods with a non-void return type are required to use the return keyword to return a value.
As noted by Eric J. and to add to the documentation (which does seem to be lacking),
Methods with a non-void return type are required to use the return keyword to return a value or throw an exception
Your method has a return
internal CommonFileDialogResult ShowDialog()
{
}
Either set it to void,
internal void ShowDialog()
{
}
or return a value
internal CommonFileDialogResult ShowDialog()
{
return null // just to get it to compile
}
If this is a required to be implemented by an interface, throw an exception
Upvotes: 1
Reputation: 150108
This method:
internal CommonFileDialogResult ShowDialog()
{
}
doesn't return anything. You must either return a CommonFileDialogResult
or throw an exception, such as
internal CommonFileDialogResult ShowDialog()
{
throw new NotImplementedException("Need to implement this.");
}
Upvotes: 2
Reputation: 77
internal CommonFileDialogResult ShowDialog()
{
}
CommonFileDialogResult indicates that you expect th method to return an object of type CommonFileDialogResul. solutions:
Upvotes: 1
Reputation: 1197
this is because your code expects a return value which isn't there in the last function
Upvotes: 0