Home > Net >  C # how to jump out of a return value is the function of type string array
C # how to jump out of a return value is the function of type string array

Time:11-05

C # how to jump out of a return value is the function of type string array!
Public string [] ListQureyDataReader ()
{
int i=0;
[DataCount string [] res2=new string ());
String res="";
SqlConnection SLQ=new SqlConnection (SQLSentence CreatStrCon (_serverAddress _databaseName));
String sqlStr=SQLTurnover. SelectOper (out res);
If (string. IsNullOrEmpty (sqlStr))
{
return;
}

How to write the return to perform certain error
How does a great god out of this function

CodePudding user response:

Return null

CodePudding user response:

A function returns a value, or throw throw exceptions, design should be standardized, are not allowed to "jump out" with a mind,

CodePudding user response:

What to return values (object or null), this is actually the logical design problem, not writing code,

CodePudding user response:

You can use the Win32 API style writing:
 
Public String ListQureyDataReader (String [] res2)
{
int i=0;
[DataCount res2=new string ()];
String res="";
SqlConnection SLQ=new SqlConnection (SQLSentence CreatStrCon (_serverAddress _databaseName));
String sqlStr=SQLTurnover. SelectOper (out res);
If (string. IsNullOrEmpty (sqlStr))
{
Return "the Result is empty.";
}

CodePudding user response:

Threw new Exception (${sqlStr} "does not allow null")

CodePudding user response:

If you are really don't know what should be returned according to the function return value type, you can write a

Return the default; Except (void)
  •  Tags:  
  • C#
  • Related