I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has no return value then I want to make return value optional, is it possible ?
I have tried with if condition.But there is error.
How can I make return value optional for the method if possible ?
You can’t make the return value optional.
Your two options are to either return a
nullor an emptyDataTable:OR:
Which one is right? It depends on your application logic and how much
nullchecking you are willing to do in your calling functions.Update: (following comment)
This is how to return conditionally (assumes a variable called dataTable):