編譯器最佳化行為(2)

  • 1696
  • 0
  • C#
  • 2013-06-15

摘要:編譯器最佳化行為(2)

使用if else寫法與使用三元運算子寫法在編譯器編譯過後的差別,在行數方面減少很多。

 

//第一種原始寫法:



    string s = "fdsaf";

	if (s == "fdsafd")
	{
		s = "ok";
	}
	else
	{
		s = "none";
	}
	return s;

 

   //第二種原始寫法: 

            string s = "fdsaf";


            string i = s == "fdsafd" ? "ok" : "none";

            return i;

 

//第一種寫法經過編譯後: 

    string s = "fdsaf";
	if (s == "fdsafd")
	{
		s = "ok";
	}
	else
	{
		s = "none";
	}
	return s;

 

//第二種寫法經過編譯後:

	string s = "fdsaf";
	string arg_20_0 = (s == "fdsafd") ? "ok" : "none";
	return s;