Tag: C#的

在C#中转义无效的XML字符

我有一个string包含无效的XML字符。 在parsingstring之前,如何转义(或删除)无效的XML字符?

C#:“types'System.InvalidOperationException'的第一个机会exception”

在C#中处理类的分配,我遇到了一个没有任何错误的程序崩溃(除了在VS2010的debugging窗口中写的东西外)。 这是导致崩溃的典型代码: public partial class Test : Form { public Test() { InitializeComponent(); } private void Test_Load(object sender, EventArgs e) { ColumnHeader header; header = new ColumnHeader(); header.Text = "#"; header.TextAlign = HorizontalAlignment.Center; header.Width = 30; listView1.Columns.Add(header); TimerCallback tcb = this.UpdateListView; System.Threading.Timer updateTimer = new System.Threading.Timer(tcb, null, 0, 1000); } public void UpdateListView(object obj) { […]

'\ 0'评估为false,“\ 0”评估为true

受K&R第5.5节中描述的程序的启发: void strcpy(char *s, char *t) { while(*s++ = *t++); } C程序 if ('\0') { printf("\'\\0\' -> true \n"); } else { printf("\'\\0\' -> false\n"); } if ("\0") { printf("\"\\0\" -> true \n"); } else { printf("\"\\0\" -> false\n"); } 版画 '\0' -> false "\0" -> true 为什么'\0'和"\0"在C中的评估方式不同? 铿锵的版本3.8.0

警告C4003和错误C2589和C2059:x = std :: numeric_limits <int> :: max();

这行在一个小testing程序中正常工作,但是在我想要的程序中,我得到了下面的编译器投诉: #include <limits> x = std::numeric_limits<int>::max(); c:\…\x.cpp(192) : warning C4003: not enough actual parameters for macro 'max' c:\…\x.cpp(192) : error C2589: '(' : illegal token on right side of '::' c:\…\x.cpp(192) : error C2059: syntax error : '::' 我得到相同的结果: #include <limits> using namespace std; x = numeric_limits<int>::max(); 为什么它将max看作macrosmax(a,b); ?

C#PredicateBuilder实体:参数'f'没有绑定在指定的LINQ to Entities查询expression式中

我需要build立一个dynamic的filter,我想继续使用实体。 因为这个原因我想用albahari的PredicateBuilder。 我创build了以下代码: var invoerDatums = PredicateBuilder.True<OnderzoeksVragen>(); var inner = PredicateBuilder.False<OnderzoeksVragen>(); foreach (var filter in set.RapportInvoerFilter.ToList()) { if(filter.IsDate) { var date = DateTime.Parse(filter.Waarde); invoerDatums = invoerDatums.Or(o => o.Van >= date && o.Tot <= date); } else { string temp = filter.Waarde; inner = inner.Or(o => o.OnderzoekType == temp); } } invoerDatums = invoerDatums.And(inner); var onderzoeksVragen […]

X509Certificate构造函数exception

//cert is an EF Entity and // cert.CertificatePKCS12 is a byte[] with the certificate. var certificate = new X509Certificate(cert.CertificatePKCS12, "SomePassword"); 从我们的数据库加载证书时,在我们的登台服务器(Windows 2008 R2 / IIS7.5)上,我们得到这个exception: System.Security.Cryptography.CryptographicException: An internal error occurred. at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) 注意:这个问题不会发生在本地(Windows 7 / Casini)。 […]

使用DataContractSerializer来序列化,但不能反序列化

我有以下两个function: public static string Serialize(object obj) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); MemoryStream memoryStream = new MemoryStream(); serializer.WriteObject(memoryStream, obj); return Encoding.UTF8.GetString(memoryStream.GetBuffer()); } public static object Deserialize(string xml, Type toType) { MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); // memoryStream.Position = 0L; XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, Encoding.UTF8, new XmlDictionaryReaderQuotas(), null); DataContractSerializer dataContractSerializer = new DataContractSerializer(toType); return dataContractSerializer.ReadObject(reader); } […]

?:?? 运算符而不是IF | ELSE

public string Source { get { /* if ( Source == null ){ return string . Empty; } else { return Source; } */ return Source ?? string.Empty; } set { /* if ( Source == null ) { Source = string . Empty; } else { if ( Source == value ) { Source […]

C ++中“std :: size_t”是否合理?

在我inheritance的一些代码中,我经常使用size_t和std命名空间限定符。 例如: std::size_t n = sizeof( long ); 它编译并运行良好,当然。 但对我来说这似乎是不好的做法(也许是从C结束?)。 是不是真的size_t内置到C ++,因此在全局命名空间? 包含在C ++中使用size_t所需的头文件? 另一个问这个问题的方法是,下面的程序( 不包括)是否可以在所有C ++编译器上编译? size_t foo() { return sizeof( long ); }

从指数表示法parsing数字

我需要将string“1.2345E-02”(一个用指数表示法表示的数字)parsing为十进制数据types,但是Decimal.Parse("1.2345E-02")只是抛出一个错误