C# Advance Functions
By karthick
, in
array functions
,
C# Advance Functions
,
c# functions
,
function with default value
,
param function
,
0 Comments
Def:
public void fun_name(string s)
{
}
Calling:
fun_name("abcd");
|
public string fun_name(string s,string s2="kart")
{
return
s = s +s2;
}
Calling:
fun_name("abcd");
fun_name("abcd",”12345”);
|
public string fun_name(params
object[] values)
{
return
values[0].ToString();
}
Calling:
fun_name("abcd");
fun_name(50);
fun_name(50.5568);
fun_name("abcd",50,50.2145);
|
public static class ObjectExtensions
{
/// <summary>
/// convert object to string with null safe and it return
string
/// </summary>
/// <param
name="obj"></param>
/// <returns></returns>
public
static string
ToSafeString(this object
obj)
{
return
obj != null ? obj.ToString() : String.Empty;
}
/// <summary>
/// convert object to string with null safe, if can't return
0
/// </summary>
/// <param
name="obj"></param>
/// <returns></returns>
public
static string
ToSafeString_0(this object
obj)
{
return
obj != null ? obj.ToString() : "0";
}
}
Calling:
.ToSafeString();
int a=null;
a.ToSafeString();
a.ToSafeString_0();
|