我的一位同事告诉我,我永远不应该使用静态变量,因为如果你在一个地方改变它们,它们就会随处变化.他告诉我,我应该使用Singleton而不是使用静态变量.我知道Singleton用于限制一个类到一个类的实例数.Singleton如何帮助我使用静态变量?
我是这样做的:
HttpContext.Current.Server.MapPath(@"~\~\~\Content\")
Run Code Online (Sandbox Code Playgroud)
我知道'.' 是为了项目的根,但如何回几个文件夹?
我想在Windows 7上创建Windows服务和桌面应用程序之间的通信.我读到命名管道是两个进程之间通信的一种方式.我可以将它们用于我的目的吗?
我想用参数颜色调用一个方法.但是有很多颜色只有阴影才有区别.我怎样才能找到与我的颜色不同的颜色,例如AntiqueWhite和Bisque.这是调色板.
Bitmap LogoImg = new Bitmap("file1.jpeg");//the extension can be some other
System.Drawing.Color x = LogoImg.GetPixel(LogoImg.Width-1, LogoImg.Height-1);
LogoImg.MakeTransparent(x);
image1.Source = GetBitmapSource(LogoImg);
Run Code Online (Sandbox Code Playgroud) 我的代码是这样的:
byte[] byteArray = Encoding.ASCII.GetBytes(someText);
MemoryStream stream = new MemoryStream(byteArray);
StreamReader reader = new StreamReader(stream);
FileStream file = (FileStream)reader.BaseStream;
Run Code Online (Sandbox Code Playgroud)
后来我正在使用file.Name.
我收到一个InvalidCastException:它显示如下
无法将类型为"System.IO.MemoryStream"的对象强制转换为"System.IO.FileStream".
我在某处读到了我应该将FileStream更改为Stream.还有什么我应该做的吗?
在我的MVC应用程序中,图像将位于App_Data文件夹中.我想在Jquery中将源代码提供给我的img标记.我是这样做的:
var src1 = <%=Url.Content(Server.MapPath("/AppData/1.jpg"))%>
$("#imgLocation").attr("src", src1);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.为什么?
这是我的代码:
a.dateFrom = DateTime.ParseExact(x, "dd/mm/yyyy", null);
Run Code Online (Sandbox Code Playgroud)
x的值为:08/03/2012
但是,a.dateFrom的值为08/01/2012.为什么?
我在我的数据库中插入一个日期,其值来自:
s.theDate = Convert.ToDateTime("06-13-2012");
Run Code Online (Sandbox Code Playgroud)
我收到错误,"字符串未被识别为有效的DateTime".我该如何解决这个问题?
$(editor[i])[0].outerHTML 具有以下值:
<p style="color: red;" data-mce-style="color: red;">some string</p>
Run Code Online (Sandbox Code Playgroud)
我想data-mce-style="color: red;"消失.
我是这样做的:
$(editor[i])[0].outerHTML.replace('data-mce-style="color: red;"', '');
Run Code Online (Sandbox Code Playgroud)
但它并没有取代它.
我有两个表Employee(n)和Store(1),它们有n:1的关系.
Employee有外键idStore是主键Store.
以下是我尝试从Employee以下位置删除行的方法:
public void deleteEmployee(int idEmployee)
{
MyEntities pe = new MyEntities();
try
{
var firstQuery = from e in pe.Employees
where e.idEmployee == idEmployee
select e;
string findIdStore = firstQuery.First().StoreReference.EntityKey.EntityKeyValues[0].Value.ToString();
int idStore = Int32.Parse(findIdStore);
Store r = pe.Stores.First(c => c.idStore == idStore);
r.Employees.Remove(firstQuery.First());
pe.DeleteObject(firstQuery.First());
pe.SaveChanges();
}
catch (Exception ex)
{
return;
}
}
Run Code Online (Sandbox Code Playgroud)
而且,我得到的错误是delete语句与引用约束冲突.
完整的错误在这里:
DELETE语句与REFERENCE约束"FK_Bill_Employee"冲突.冲突发生在数据库"myDatabase",表"dbo.Bill",列"idEmployeeMember"中.
该语句已终止.
c# ×7
jquery ×2
asp.net ×1
colors ×1
datetime ×1
filestream ×1
iis ×1
javascript ×1
memorystream ×1
named-pipes ×1
singleton ×1
static ×1
stream ×1
windows-7 ×1