我正在使用下面的示例代码来编写和下载内存流到C#中的文件.
MemoryStream memoryStream = new MemoryStream();
TextWriter textWriter = new StreamWriter(memoryStream);
textWriter.WriteLine("Something");
byte[] bytesInStream = new byte[memoryStream.Length];
memoryStream.Write(bytesInStream, 0, bytesInStream.Length);
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition",
"attachment; filename=name_you_file.xls");
Response.BinaryWrite(bytesInStream);
Response.End();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
指定的参数超出了有效值的范围.
参数名称:offset
可能是什么原因?
在下面的代码"objTo"是一个div我需要插入多个div.当我第一次使用代码工作时,但下次它会覆盖现有代码.
<script>
var divtest= document.createElement("div");
divtest.innerHTML = "<div>new div</div>"
objTo.appendChild(divtest)
</script>
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我遇到了不同的创作和结构设计模式.
在构建器中它有三个部分,导演将决定执行的顺序.
当我浏览外观模式时,它也遵循相同的操作顺序的方法.
那么这两种模式的区别是什么?当Facade模式也指对象的创建和执行顺序时,它如何属于结构设计模式?
在下面的适配器设计模式示例代码中,为什么要引入新类而不是在客户端中使用多个接口?
interface ITarget
{
List<string> GetProducts();
}
public class VendorAdaptee
{
public List<string> GetListOfProducts()
{
List<string> products = new List<string>();
products.Add("Gaming Consoles");
products.Add("Television");
products.Add("Books");
products.Add("Musical Instruments");
return products;
}
}
class VendorAdapter:ITarget
{
public List<string> GetProducts()
{
VendorAdaptee adaptee = new VendorAdaptee();
return adaptee.GetListOfProducts();
}
}
class ShoppingPortalClient
{
static void Main(string[] args)
{
ITarget adapter = new VendorAdapter();
foreach (string product in adapter.GetProducts())
{
Console.WriteLine(product);
}
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下与上述代码相关的查询.
我有下面的列表和查询表达式来获取不同的列表。
List<LinqTest> myList = new List<LinqTest>();
myList.Add(new LinqTest() { id = 1, value = "a" });
myList.Add(new LinqTest() { id = 1, value = "b" });
myList.Add(new LinqTest() { id = 2, value = "c" });
myList.Select(m => new { m.id}).Distinct().ToList();
Run Code Online (Sandbox Code Playgroud)
我已经提到了下面SO链接链接的代码。即使在使用distinct()之后,我也获得了3个具有重复值的记录。可能是什么原因?
public void Invoke(string methodname)
{
string funcname=methodname.Split('.')[1];
//funcname contains the value of CustomerController
Type type = typeof(funcname);
MethodInfo method = type.GetMethod(funcname);
CustomerController c = new CustomerController();
string result = (string)method.Invoke(c, null);
}
Run Code Online (Sandbox Code Playgroud)
在这里我需要将一个字符串值传递给typeof一个类名的表达式.但我得到编译时错误.在上面的代码中
Type type = typeof(funcname);
Run Code Online (Sandbox Code Playgroud)
这里funcname包含值"CustomerController".如果我用下面的行替换它,它工作正常.
Type type = typeof(CustomerController);
Run Code Online (Sandbox Code Playgroud)
如何将字符串值传递给typeof表达式?