我在(oracle)資料庫中有一個表,它有一列NUMBER(12). 我不能int在 C# 中使用,因為它很小,所以我使用了long. 但是long對于這個表列來說太大了。long在將資料發送到資料庫之前,有沒有辦法限制 a 的大小?否則我將收到錯誤 ORA-21525,因為我超出了表列的大小。發送到資料庫的資料實際上是一個List<long>.
uj5u.com熱心網友回復:
最明顯的解決方案是使用限制數字值范圍的自定義數字型別。就像是
public readonly struct Number12{
public long Value {get;}
public Number12(long num){
if(num > 999999999999 || num < -999999999999 ){
throw new ArgumentException("number out of rage " num);
}
Value = num;
}
// Add operators, conversions etc
}
這樣做的一個優點是很明顯這個數字有一些特殊的規則。但是使用起來會比較麻煩,而且如果以后改資料庫可能會出現問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347537.html
標籤:C# 。网 甲骨文 .net-framework-4.8
上一篇:雙擊串列框項–C#
