我正在寻找一种在C#或.NET中执行指针操作的方法.
我想做一些非常简单的事情
有一个指针IntPtr我想获得指向前2个字节的IntPtr对象.
我读了一些帖子,说这个愚蠢的片段会起作用......
IntPtr ptr = new IntPtr(oldptr.ToInt32() + 2);
Run Code Online (Sandbox Code Playgroud)
但我怀疑这个语句是否也适用于64位机器(因为在那里寻址是64位).
我发现这种优雅的方法来添加偏移量,但不幸的是只在.NET 4.0中http://msdn.microsoft.com/en-us/library/system.intptr.add%28VS.100%29.aspx
这里我下载了GetSourceAttachment方法的word文件.当这个方法返回空字节然后我的字节附件数组给出一个错误(对象引用没有设置对象的实例).当我在条件中检查附件的长度然后它给出错误.任何人都可以帮我默认初始化字节数组然后检查长度.
try
{
byte[] Attachment = null ;
string Extension = string.Empty;
ClsPortalManager objPortalManager = new ClsPortalManager();
Attachment = objPortalManager.GetSourceAttachment(Convert.ToInt32(hdnSourceId.Value), out Extension);
if (Attachment.Length > 0 && Attachment != null)
{
DownloadAttachment("Attacment", Attachment, Extension);
}
else
{
ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", "<script type='text/javascript'>alert('Attachment is not Uploaded !');</script>");
}
}
catch
{
}
Run Code Online (Sandbox Code Playgroud) 这可能吗?代码示例会很好.
我正在为十进制验证器编写一个自定义字符串,需要使用忽略文化的Decimal.TryParse(即不关心输入是否包含"."或","作为小数点分隔符).这是建议的方法:
public static bool TryParse(
string s,
NumberStyles style,
IFormatProvider provider,
out decimal result
)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚要用什么作为第三个参数.我见过的例子如下:
culture = CultureInfo.CreateSpecificCulture("en-GB");
Decimal.TryParse(value, style, culture, out number)
Run Code Online (Sandbox Code Playgroud)
所以他们创造了一种特定的文化 CultureInfo没有"CreateInvariantCulture"方法,CultureInfo.InvariantCulture不是必需的类型.什么是正确的用法?
可以将扩展方法分配给与对象的用法匹配的委托,如下所示:
static class FunnyExtension {
public static string Double(this string str) { return str + str; }
public static int Double(this int num) { return num + num; }
}
Func<string> aaMaker = "a".Double;
Func<string, string> doubler = FunnyExtension.Double;
Console.WriteLine(aaMaker()); //Prints "aa"
Console.WriteLine(doubler("b")); //Prints "bb"
Run Code Online (Sandbox Code Playgroud)
如果他们扩展的类型是值类型,它将不起作用:
Func<int> eightMaker = 4.Double; //Error CS1113: Extension methods 'FunnyExtension.Double(int)' defined on value type 'int' cannot be used to create delegates
Func<int, int> intDoubler = FunnyExtension.Double; //Works
Run Code Online (Sandbox Code Playgroud)
这给了
错误CS1113:在值类型"int"上定义的扩展方法'FunnyExtension.Double(int)'不能用于创建委托.
他们为什么不能?
我在某些用户计算机上生成了这个异常(约20个中的1个):
无法加载文件或程序集'System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一.该系统找不到指定的文件.
我在网站和本网站上发现了几个对此错误的引用,但没有任何帮助.
我有一个使用WCF连接到服务器的加载项应用程序.使用带有VS 2008的.NET Framework 3.5构建的加载项.
该错误只能在一个用户帐户中的一台测试机器上重现.我安装我的应用程序,只能从这台机器上的一个帐户重现这个,除此之外它工作正常.此外,只有一个版本的主机应用程序可以重现,我为其创建了加载项(我假设它使用了不同的.NET框架).
我检查了保险丝日志,我看到以下内容:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files\SolidWorks Corp\SolidWorks\sldworks.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Home\User
LOG: DisplayName = System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/SolidWorks Corp/SolidWorks/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, …Run Code Online (Sandbox Code Playgroud) 我要将字节数组转换为System.Windows.Media.Imaging.BitmapImage并BitmapImage在图像控件中显示.
当我使用第一个代码时,注意到了!没有错误,也没有显示图像.但是当我使用第二个时,它工作正常!任何人都可以说发生了什么事吗?
第一个代码在这里:
public BitmapImage ToImage(byte[] array)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(array))
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = ms;
image.EndInit();
return image;
}
}
Run Code Online (Sandbox Code Playgroud)
第二个代码在这里:
public BitmapImage ToImage(byte[] array)
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = new System.IO.MemoryStream(array);
image.EndInit();
return image;
}
Run Code Online (Sandbox Code Playgroud) 基类中的赋值运算符似乎在派生类中不可用.鉴于此代码:
#include <iostream>
class A{
int value;
public:
A& operator=(int value){
this->value = value;
return *this;
}
};
class B : public A{};
int main(){
B b;
b = 0; // Does not work
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC 6.4说:
错误:'operator ='不匹配(操作数类型为'B'和'int')
怎么了?
我想根据数据集的结果重定向到不同的视图,但我一直回到我当前所在的页面,并且无法解决原因.我进入if语句调用操作但是一旦我将视图返回到新页面,它就会返回到当前页面.
CSHTML页面
@{
ViewBag.Title = "Search Results";
EnumerableRowCollection<DataRow> custs = ViewBag.Customers;
bool anyRows = custs.Any();
if(anyRows == false)
{
Html.Action("NoResults","Home");
}
// redirect to no search results view
Run Code Online (Sandbox Code Playgroud)
}
调节器
public ActionResult NoResults()
{
return View("NoResults");
}
Run Code Online (Sandbox Code Playgroud)
查看我也无法得到..
@{
ViewBag.Title = "NoResults";
}
<h2>NoResults</h2>
Run Code Online (Sandbox Code Playgroud) 我有3个文本视图.我需要将它们的重量设置为Light,Regular和Condensed.有人可以帮助我如何在Android中实现这一目标吗?
c# ×8
.net ×4
android ×1
bitmapimage ×1
bytearray ×1
c++ ×1
cultureinfo ×1
decimal ×1
delegates ×1
frameworks ×1
inheritance ×1
interop ×1
pinvoke ×1
razor ×1
textview ×1
tryparse ×1
uitextview ×1
value-type ×1
wpf ×1