有人可以向我解释一下之间的区别:
Session.Add("name",txtName.text);
和 Session["name"] = txtName.text;
这是一个面试问题,我回答说两者都以C#中的类key = "Value"
格式存储数据Dictionary
.
我是对的,还是有什么区别?
我有一个导入EF4的存储过程,当我在30秒后用某些参数调用它时会抛出超时错误.在SQL Server探查器中,我可以看到存储过程调用使用适当的参数只需要超过30秒,这是我的应用程序的超时.
但是,当我执行在查询分析器中发送到探查器的相同SQL时,它会执行亚秒级.什么可能导致从EF调用和从SQL Server Management Studio调用之间的这种差异?
下面是.NET错误的完整堆栈跟踪.
[SqlException(0x80131904):超时已过期.操作完成之前经过的超时时间或服务器没有响应.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)+2073486
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection)+5064444
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()+234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2275
System.Data.SqlClient. SqlDataReader.ConsumeMetaData()+ 33
System.Data.SqlClient.SqlDataReader.get_MetaData()+86
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)+311
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)+987
System.Data.SqlClient.SqlCommand.RunExecuteReade r(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,DbAsyncResult结果)+162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)+32
System.Data.SqlClient.SqlCommand .ExecuteReader(CommandBehavior behavior,String method)+141
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)+12
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)+10 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands (EntityCommand entityCommand,CommandBehavior behavior)+443[EntityCommandExecutionException:执行命令定义时发生错误.详情请参阅内部异常.]
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,行为的CommandBehavior)479
System.Data.Objects.ObjectContext.CreateFunctionObjectResult(EntityCommand entityCommand,EntitySet的EntitySet的,EdmType edmType,MergeOption mergeOption)+ 182
System.Data.Objects.ObjectContext.ExecuteFunction(字符串functionName,而MergeOption mergeOption,ObjectParameter []参数)218
System.Data.Objects.ObjectContext.ExecuteFunction(字符串functionName,而ObjectParameter []参数)53个
MetaView.DAL.MFCMData.MFCMDATAEntities .GetTradingOpenPositionCounterParty(可空1 positionDT, Nullable
1个tradingAccountID)在C:\项目\ CASH \网络\ MetaView\MetaView.DAL.MFCMData\MFCMData.Designer.cs:7064个MetaView.BusinessLayer.Shared.Accounts.CounterParties.GetCounterParties(的Int32 tradingAccountID)在C: …
调节器
public ActionResult Search(string id)
{
id= Request.QueryString["term"];
var routeList = db.Movies.Where(r => r.Title.Contains(id))
.Take(5)
.Select(r => new { id = r.MovieID, label = r.Title, name = "MovieID" });
return Json(routeList, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
视图:
<input type="hidden" id="MovieID" name="MovieID" />
<input type="text" id="SelectedMovie" value=""/>
<script type="text/javascript" language="javascript">
$("#SelectedMovie").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Transaction/Search", type: "POST", dataType: "json",
data: { id: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.label, value: item.id }; //updated …
Run Code Online (Sandbox Code Playgroud) 我目前正在考虑移植我的metro哈希实现以使用C#7功能,因为有些部分可能会从ref本地人那里获益以提高性能.哈希在ulong[4]
数组上进行计算,但结果是16个byte
数组.目前我正在将ulong
数组复制到结果byte
缓冲区,但这需要一些时间.所以我想知道在System.Runtime.CompilerServices.Unsafe
这里使用是否安全:
var result = new byte[16];
ulong[] state = Unsafe.As<byte[], ulong[]>(ref result);
ref var firstState = ref state[0];
ref var secondState = ref state[1];
ulong thirdState = 0;
ulong fourthState = 0;
Run Code Online (Sandbox Code Playgroud)
上面的代码片段意味着我也使用结果缓冲区来进行状态计算的部分,而不仅仅是最终输出.
我的单元测试是成功的,并且根据benchmarkdotnet跳过块复制将导致20%的性能提升,这足以让我发现它是否正确使用它.
我想知道在datagridview中遍历所有行并从单元格中获取值的最佳方法是什么.
这是我在想的事情,但我不是很喜欢它,因为如果我重新排列列,那么代码也必须改变.
for (int i = 0; i < dataGridView.RowCount; i++)
{
string Value0 = dataGridView1.Rows[i].Cells[0];
string Value1 = dataGridView1.Rows[i].Cells[1];
string Value2 = dataGridView1.Rows[i].Cells[2];
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我现有的MVC Web应用程序编写单元测试.因为我在automapper(IMapper
)中遇到一些问题每当使用map函数时它返回null
值.
我的控制器代码:
public class UserAdministrationController : BaseController
{
private readonly iUserService _userService;
private readonly IMapper _mapper;
public NewsController(iUserService userService, IMapper mapper)
{
_userService = userService;
_mapper = mapper;
}
public ActionResult Create(int CompanyID == 0)
{
UserDetail data = _userService(CompanyID);
var Modeldata = _mapper.Map<UserDetailViewModel, UserDetail>(data);
return View(Modeldata);
}
}
Run Code Online (Sandbox Code Playgroud)
模拟映射代码:
public class MappingDataTest : CommonTestData
{
public Mock<IMapper> MappingData()
{
var mappingService = new Mock<IMapper>();
UserDetailViewModel interview = getUserDetailViewModel(); // get value of UserDetailViewModel
UserDetail …
Run Code Online (Sandbox Code Playgroud) -----要求修改代码--------
问题:计算具有50个因子的快速三角系列号?
详细说明:让我们说有一系列
1 : 1
3 : 1+2
6 : 1+2+3
10 : 1+2+3+4
15 : 1+2+3+4+5
21 : 1+2+3+4+5+6
28 : 1+2+3+4+5+6+7
Run Code Online (Sandbox Code Playgroud)
这里1,3,6,10,15,21,28是三角形系列下的数字.
让我们看看数字的因素
Number factors Count
1 : 1 1
3 : 1,3 2
6 : 1,2,3,6 4
10 : 1,2,5,10 4
15 : 1,3,5,15 4
21 : 1,3,7,21 4
28 : 1,2,4,7,14,28 6
Run Code Online (Sandbox Code Playgroud)
这里6是第一个具有4个因子的三角形数字.即使10,15,21也有4个因素,但它们不是第1个.就像那样,让一个数字为2,其中2个因子为1,2个数字3相同,也有2个因子为1和3
但根据问题3,答案不是2,因为即使它快于3,2也不会进入三角系列号列表.
我正面临一个严重的问题.我想在HTML表中显示所有用户及其状态.是否可以使用javascript?
我已经通过以下链接,它只显示一个用户,它的状态和用户邮件ID是硬编码的.
在ASP.NET页面中集成Microsoft Office Communicator 2007
使用Javascript
<script type="Javascript">
var sipUri = "your.contact@your.domain.com";
var nameCtrl = new ActiveXObject('Name.NameCtrl.1');
if (nameCtrl.PresenceEnabled)
{
nameCtrl.OnStatusChange = onStatusChange;
nameCtrl.GetStatus(sipUri, "1");
}
function onStatusChange(name, status, id)
{
// This function is fired when the contacts presence status changes.
// In a real world solution, you would want to update an image to reflect the users presence
alert(name + ", " + status + ", " + id);
}
function ShowOOUI()
{
nameCtrl.ShowOOUI(sipUri, 0, 15, 15); …
Run Code Online (Sandbox Code Playgroud) 是否有可能只读一个数组.这样就不允许将值设置为数组.
这里我尝试使用readonly关键字来声明数组.然后我通过使用IsReadOnly属性检查该数组是否只读.但它永远不会回归真实.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrivateExposeConsoleApp
{
class Program
{
private static readonly int[] arr = new int[3] { 1,2,3 };
static void Main(string[] args)
{
// Create a read-only IList wrapper around the array.
IList<int> myList = Array.AsReadOnly(arr);
try
{
// Attempt to change a value of array through the wrapper.
arr[2] = 100;
Console.WriteLine("Array Elements");
foreach (int i in arr)
{
Console.WriteLine("{0} - {1}", i + "->", i);
}
Console.WriteLine("---------------");
Console.WriteLine("List Elements"); …
Run Code Online (Sandbox Code Playgroud) 我试图从数据写FileStream
,StreamWriter
一个字的文件.
当数据是文本格式(使用StreamWriter
)时,它工作正常.但是,当我尝试使用Binarywriter
(用于将图像写入word doc)时,它正在错误地写入word文档.
在下面的代码中lstOrderedSpares[index].SparePicture
是包含图像数据的字节数组.
我需要一个没有OPENXML的解决方案.
这是我到目前为止所尝试的:
这是我的按钮单击,我将数据初始化为类和 List
private void btnCreateQuotation_Click(object sender, EventArgs e)
{
try
{
Quotation aQuotation = new Quotation();
aQuotation.QuotationId = quotationId;
aQuotation.QuotationDate = lblQuotationDateValue.Text;
//Reading from Datagridview and adding to List<Spare>
List<Spare> lstOrderedSpares = new List<Spare>();
if (dataGridView1.Rows.Count > 0)
{
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
Spare aSpare = new Spare();
aSpare.SapreSerialNumber = dr.Cells["SlNo"].Value.ToString();
aSpare.SparePartId = dr.Cells["SparePartID"].Value.ToString();
aSpare.SparePicture = (byte[])dr.Cells["SparePicture"].Value;
aSpare.SpareDescription = dr.Cells["SpareDescription"].Value.ToString();
aSpare.EURPrice = …
Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×2
asp.net ×2
asp.net-mvc ×2
jquery ×2
algorithm ×1
arrays ×1
automapper ×1
c#-7.0 ×1
datagridview ×1
javascript ×1
mocking ×1
ms-word ×1
readonly ×1
session ×1
unit-testing ×1
windows ×1
winforms ×1