Implementation .NET framework with unlimited parameters () function

zhaozj2021-02-11  176

Console.Writeline in the .NET Framework library supports up to 3 parameters, very inconvenient to use, although C supports a WriteLine of an unlimited parameter, but VB and C # and other large number of languages ​​are not supported. Now, I have written a VB function, and he uses the function of parameter array in VB, C # and JScript, implements unlimited parameters of Wrtieline. The reason for writing with VB is that VB contains many simple string functions, which can greatly simplify the program. After compiling into components, C # is available.

Public Shared Sub Writeline (byval format as string, byval paramarray args () as object) '******************************************* ************************************* '* author: Ninputer' * date: August 2001 27th '*' * Parameters: Format is the output string, where the output content "* args () is the output content, can have an unlimited parameter, match the corresponding location in Format '* Return value: no' * Description : Provide a WriteLine method for unlimited parameters, more convenient than System.Console '******************************************** ***************************************

DIM SSUBSTRING, SSUBSTRINGRP AS STRING DIM I, J AS INTEGER

If args.length = 0 THEN Console.writeline (Format) Else 'Adds the output of unlimited parameters

If format = "" "If there is no string, skip the loop search section console.writeline (" ") EXIT SUB END IF

Try i = 1 'Current character pointer location Do if Format.chars (i - 1) = "{" THEN J = INSTR (i, format, "}")' J starts from i, the first "}" s position

'Intercepted SSUBSTRING = Format.Substring (i, J - i - 1)' Like "3" ssubstringrp = format.substring (i - 1, j - i 1) 'Like "{ 3} "

转载请注明原文地址:https://www.9cbs.com/read-5117.html

New Post(0)