在我的数据库中,v1字段是可空字段.但如果值为null,我定义0(默认值).
public decimal? v1 {
get {
return this._v1;
}
set {
this._v1 = value ?? 0M;
}
}
Run Code Online (Sandbox Code Playgroud)
所以现在,v1不再是可空变量了.
但我不能这样做,
decimal v2 = v1;
Run Code Online (Sandbox Code Playgroud)
错误信息说,不能隐式转换类型'decimal?' 到'十进制'.
在这种情况下,我是否必须转换为十进制,像这样?
decimal v2 = Convert.ToDecimal(v1);
Run Code Online (Sandbox Code Playgroud)
这是非常讨厌的工作.而且代码看起来也很脏.
谁知道更好的解决方案 请指教.
我想在构造函数方法中将cookie值定义为类变量,以使所有方法都可以使用Cookie.
但我收到一条错误消息,
你调用的对象是空的.
public class OrdersController : Controller
{
string userData;
public orderConroller(){
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Request.Cookies[cookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
userData = authTicket.UserData;
}
public void a(){
//I need Cookie
}
public void b(){
//I need Cookie
}
public void c(){
//I need Cookie
}
public void d(){
//I need Cookie
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?@.@
谢谢!
每个继承类的方法都需要不同类型的参数.在这种情况下,我应该如何在Interface Method中定义参数才能使所有子方法都能接受?
public interface IPayment
{
void MakePayment(OrderInfo orderInfo); // !!
void MakeRefund (OrderInfo orderInfo); // !!
}
public class OrderInfo
{
protected string OrderNo {get; set;}
protected string CustomerNo { get; set;}
protected decimal Amount {get; set;}
}
public class CreditCardPaymentInfo : OrderInfo
{
string CCNum {get; set;}
string ExpDate { get; set;}
}
public class GooglePaymentInfo : OrderInfo
{
string GoogleOrderID {get; set;}
}
public class PaypalPaymentInfo : OrderInfo
{
string PaypalID {get; set;}
}
public void MakePayment() …Run Code Online (Sandbox Code Playgroud) 我正在使用引用参数来返回多个信息.喜欢,
int totalTransaction = 0;
int outTransaction = 0;
int totalRecord = 0;
var record = reports.GetTransactionReport(searchModel, out totalTransaction, out outTransaction, out totalRecord);
Run Code Online (Sandbox Code Playgroud)
//并且方法是这样的,
public List<TransactionReportModel> GetAllTransaction(
TransactionSearchModel searchModel,
out totalTransaction,
out totalTransaction,
out totalRecord) {
IQueryable<TransactionReportModel> result;
// search
return result.ToList();
}
Run Code Online (Sandbox Code Playgroud)
但我不喜欢长参数,所以我试图用单个参数清理它,使用Dictionary.
Dictionary<string, int> totalInfos = new Dictionary<string, int>
{
{ "totalTransaction", 0 },
{ "outTransaction", 0 },
{ "totalRecord", 0 }
};
var record = reports.GetTransactionReport(searchModel, out totalInfos);
Run Code Online (Sandbox Code Playgroud)
但仍然不够好,因为关键字符串没有得到承诺,就像硬条一样.
我需要使用Constant作为键吗?还是针对那种情况的更好的解决方案
I can see some examples on the internet that's using getter method.
something like this,
setId(id: number) {
this._id = id;
}
get id() {
return this._id;
}
Run Code Online (Sandbox Code Playgroud)
What're the benefits using that? beside using getId()
为了在无头模式下运行chrome,我做到了
alias chrome ="/ Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome"
chrome --remote-debugging-port = 9222 --disable-gpu --headless
在控制台,但是,我收到此错误,
[0305/140111.481537:错误:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file/var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305/140111.484254:错误:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file/var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305/140111.484254:INFO:crashpad_client_mac.cc(292) )]在0.983s中重新启动处理程序[0305/140111.513641:错误:gpu_process_transport_factory.cc(1009)]丢失UI共享上下文.[0305/140111.513709:错误:instance.cc(49)]无法找到度量标准的服务清单[0305/140111.513733:错误:service_manager.cc(890)]无法解析服务名称:metrics [0305/140111.514229:错误:socket_posix .cc(142)] bind()返回错误,errno = 48:地址已在使用中(48)
DevTools监听ws:// [:: 1]:9222/devtools/browser/c46563ca-1891-48bd-bdd6-e6122f3f3b5d [0305/140112.484141:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database .initialized on file/var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305/140112.484641:INFO:crashpad_client_mac.cc(292)]重新启动0.985s中的处理程序[0305/140113.489618:错误:xattr. cc(64)] setxattr org.chromium.crashpad.database.initialized on file/var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305/140113.490274:INFO:crashpad_client_mac.cc(292)]重新启动处理程序在0.979s [0305/140114.484881:错误:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file/var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305 /140114.485349:INFO:crashpad_client_mac.cc(292)]重启处理程序在0.985s [0305/140115.489188:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file/var/folders/m3/92mmh2 1n0cx4ppf8c3bcns38hd4_kk/T /:不允许操作(1)[0305/140115.489638:INFO:crashpad_client_mac.cc(292)]在0.985s中重启处理程序
我也试过了,
/ Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome --remote-debugging-port = 9222 --disable-gpu --headless
但我得到了同样的错误.
这有什么解决方案吗?
我有一种情况,我可能想按订单号或名称搜索.我知道我可以Where为我的LINQ查询添加一个表达式,但我只想为我正在搜索的属性添加它!我不知道在调用方法之前会提供哪个参数,那么如何添加正确的条件呢?
public JsonResult Search(int orderNo=0, string firstName="", string lastName="")
{
if (orderNo >0){
//add Condition
}
if (firstName.Length > 0){
//add Condition
}
if (lastName.Length > 0){
//add Condition
}
//get Result
var result = Repository.Orders.Where(???).OrderByDescending(e=> e.orderNo);
//return
}
Run Code Online (Sandbox Code Playgroud) 我想知道为什么我需要在下面的代码中将返回语法放两次,
public string test(){
bool a = true;
if(a){
string result = "A is true";
}else{
string result = "A is not true";
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
它会出现一个错误,表示当前上下文中不存在名称"result".
但不管怎样,都有结果变量.嗯..
所以我改变了这样的代码,
public string test(){
bool a = true;
if(a){
string result = "A is true";
return result;
}else{
string result = "A is not true";
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
然后它工作.这样使用是否正确?
请告诉我,
谢谢!
//I need to deifne productQuery here
if (test == true)
{
var productQuery = ordersRepository.ProductIn; //it returns IQueryable<ProductIn> type
}
else
{
var productQuery = ordersRepository.ProductOut; //it returns IQueryable<ProductOut> type
}
Run Code Online (Sandbox Code Playgroud)
如何定义productQuery变量?
谢谢!
[编辑]
dynamic productType;
if (test == true)
{
productType = ordersRepository.ProductIn; //it returns IQueryable<ProductIn> type
}
else
{
productType = ordersRepository.ProductOut; //it returns IQueryable<ProductOut> type
}
var productQuery = productType as IQueryable<ProductIn>;
if (productQuery == null)
{
productQuery = productType as IQueryable<ProductIn>;
}
Run Code Online (Sandbox Code Playgroud)
我这样做,是不是正确的方式?
[编辑]
我再次组织我的问题,
参数模型
public class PaymentModel
{
...
}
public class CCPaymentModel : PaymentModel
{
...
}
public class PaypalPaymentModel : PaymentModel
{
...
}
public class GooglePaymentModel : PaymentModel
{
...
}
Run Code Online (Sandbox Code Playgroud)
接口类
public interface IPayment<T> where T : PaymentModel
{
...
}
Run Code Online (Sandbox Code Playgroud)
模型(从IPayment获得继承),
public class SagePayment
: IPayment<CreditCardPaymentInfo>
{
public void MakePayment( CreditCardPaymentInfo creditCardPaymentInfo ) {
// ...
}
public void MakeRefund( CreditCardPaymentInfo creditCardPaymentInfo ) {
// ...
}
}
public class GooglePayment
: IPayment<GooglePaymentModel>
{
public void …Run Code Online (Sandbox Code Playgroud) 我通过网络搜索找到了下面的代码,我不明白为什么作者在该类中使用枚举.这是为了限制价值吗?是这样,WhichSex只能采用"男性"和"女性"字符串值吗?
public class Person
{
public enum Sex
{
Male,
Female,
}
public string Name { get; set; }
public bool Moustache { get; set; }
public bool Goatee { get; set; }
public bool Beard { get; set; }
public Sex WhichSex { get; set; }
public double Height { get; set; }
public DateTime BirthDate { get; set; }
public bool Favorite { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 从我的本机应用程序中,我需要打开另一个由 Ionic 构建的应用程序。
我是这样试的
val intent = packageManager.getLaunchIntentForPackage("com.example.app")
intent.putExtra("uri", "hello 2?")
intent.data = Uri.parse("hello?")
startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
它可以启动应用程序,但它从未调用过 handleOpenURL() 方法。
所以我想尝试使用自定义 URL 方案而不是包名称。
如何使用带有 URI 参数的自定义 URL 方案打开另一个应用程序?
现在我正在学习Android开发,在关注我的书时,我只是想知道为什么在SQLite列名中使用大写字母?
db.execSQL("CREATE TABLE DRINK (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "NAME TEXT, "
+ "DESCRIPTION TEXT, "
+ "IMAGE_RESOURCE_ID INTEGER);")
Run Code Online (Sandbox Code Playgroud)
通常,我使用小写字母和_仅用于Web开发.
有什么理由吗?像代码标准?