延遲求值主動求值

2021-07-14 19:15:59 字數 1364 閱讀 9615

using system;

using system.collections.generic;

using system.componentmodel.dataannotations.schema;

using system.linq;

using system.net.sockets;

using system.runtime.interopservices;

using system.text;

using system.threading.tasks;

using system.data.linq;

namespace 延遲求值主動求值

;//temp1建立乙個查詢,迭代查詢集合的值,不是立即執行

var temp1 = from c in list where c > 5 select c;

//對查詢呼叫toarray()、tolist()方法會立即執行

var temp2 = (from c in list where c > 5 select c).toarray();

list[0] = 11;

console.writeline("temp1:");

foreach (var i in temp1)

console.writeline("\ntemp2:");

foreach (var i in temp2)

console.readline();

// datacontext ctx=new datacontext("資料庫連線串");

//tablepersons = ctx.gettable();

//#region 方法1:asenumerable方法將資料庫資料轉化為本地資料

//var tem1 = (from p in persons where p.age > 20 select p).asenumerable();

//var tem2 = (from p in tem1 where p.name.indexof('e') > 0 select p);

//#endregion

//#region linq to sql

//var tempp1 = from p in persons where p.age > 20 select p;

//var tempp2 = from p in tempp1 where p.name.indexof('e') > 0 select p;

//#endregion

}//延遲查詢效能優化

}///[table(name = "person")]

class person

[column]

public int age }}

分段函式求值

上機內容 用if else語句求解分段函式。上機目的 學會分支結構程式設計。作 者 李洋 完成日期 2012 年 10月 23日 版 本 號 v1.0 輸入描述 x,x為非負數。問題描述 求以x為自變數的分段函式的值。程式輸出 y的值。問題分析 略 演算法設計 輸入x後,判斷是否為非負數。當是非負數...

分段函式求值

上機內容 用if elsse語句和switch語句求解分段函式 上機目的 學會分支結構程式設計 作 者 李全港 完成日期 2012 年 10月22 日 版 本 號 v1.0 輸入描述 x x 為非負數 問題描述 求以 x 為自變數的分段函式的值,y x 0 x 2 y x 2 2 2 x 6 y x...

字尾式求值

time limit 1000ms memory limit 65536k 有疑問?點這裡 對於乙個基於二元運算子的字尾表示式 基本運算元都是一位正整數 求其代表的算術表示式的值。輸入乙個算術表示式的字尾式字串,以 作為結束標誌。求該字尾式所對應的算術表示式的值,並輸出之。59 684 3 57 基...