【c# – 将int转换为十进制选择放置小数位的位置】教程文章相关的互联网学习教程文章

c#-将具有多个froms的linq查询表达式转换为扩展方法语法【代码】

这个问题已经在这里有了答案: > Nested “from” LINQ query expressed with extension methods 3个我在将此代码转换为扩展方法语法时遇到麻烦:var query = from c in _context.Customersfrom o in c.Orderswhere o.DateSent == nullselect new CustomerSummary{Id = c.Id,Username = c.Username,OutstandingOrderCount = c.Orders.Count};有任何想法吗?解决方法: va...

如何从C#转换(和马歇尔)CityHash std :: pair到C,反之亦然【代码】

CityHash允许我们生成128位哈希,但是将整数的128位表示形式定义为一对uint64(如header of CityHash.h所示):typedef boost::uint64_t uint64; typedef std::pair<uint64, uint64> uint128;我有一个.NET包装器,它允许我调用64位版本的城市哈希:public ref class CityHashDotNet { public:inline static void CityHash64Batch(const char* const value, uint64* const hashes, const int numValues){// I have a wrapper for CityHa...

C#转换错误【代码】

我从下面显示的代码中收到以下错误,并且找不到正确投射对象的方法.任何帮助,不胜感激. 该错误发生在ex = e.ExceptionObject;上.线.Cannot implicitly convert type ‘object’ to ‘System.Exception’. Anexplicit conversion exists (are you missing a cast?) (CS0266) –C:\DocmentMDB\DocumentMDB.ConvertedToC#\ErrorHandler.cs:59,9public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventAr...

c#-将接口数组转换为结构数组时,隐式强制转换无效【代码】

我有一个实现某些接口的结构.直到我有一个struct实现的数组,并尝试将该数组隐式转换为接口类型的另一个数组,此方法才能正常工作. (请参见下面的代码示例)using System.Collections.Generic;namespace MainNS {public interface IStructInterface{string Name { get; }}public struct StructImplementation : IStructInterface{public string Name{get { return "Test"; }}}public class MainClass{public static void Main(){Struc...

c#-.NET从十六进制值的字符串转换为Unicode字符(支持不同的代码页)【代码】

我有一串十六进制值…String hexString = "8A65";我需要将此字符串转换为它们的Unicode等效项.棘手的部分是我需要支持不同的代码页,并且某些代码页的’8A65’=一个字符,而其他代码页会将其转换为两个字符. 在需要执行转换之前,我不知道将使用哪个代码页. 我尝试过各种东西,例如byte[] original = Encoding.Unicode.GetBytes(hexString); byte[] conv= Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(932), orig); char[...

C#-对象转换【代码】

据我所知,如果要处理COM接口,通常任何简单的转换都将触发QueryInterface例程,该例程用于确定对象是否实际实现了相应的COM接口.object whatever; IComInterface casted = (IComInterface) whatever;因此,以下代码(取决于编译器和优化方式)可能会在内部对象强制转换实现中触发QueryInterface:IComInterface comInteface;// I guess nothing COM-related happens here, but I might be wrong object whatever = comInteface; // This...

通过MSCOMM从VB6转换为C#到串行端口【代码】

我正在尝试向通过串口工作的LED显示器发送一些数据.这段代码通过VB6完成了工作,但我需要将其转换为C#.不幸的是,它不起作用.有任何想法吗? VB6(示例)MSComm1.CommPort = 1MSComm1.Settings = "9600,N,8,1"MSComm1.PortOpen = TrueMSComm1.Output = Chr(170)MSComm1.Output = Chr(2)C#(示例)var serialPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);serialPort1.Open();serialPort1.Write(((char)170).ToStr...

c#-在Solver Foundation中将字符串转换为约束“ Term”【代码】

我正在尝试使用Solver Foundation创建一个能够解决线性编程问题的应用程序.长话短说,我在尝试将字符串表达式转换为Microsoft.SolverFoundation.Services.Term时遇到了麻烦. 我想要做的是将字符串作为约束添加到模型,但是首先必须将其转换为“术语”.SolverContext context = SolverContext.GetContext(); Model model = context.CreateModel();Decision vz = new Decision(Domain.IntegerNonnegative, "barrels_venezuela"); Decis...

c#-将双精度数转换为十进制数,并在需要时将其上限【代码】

我有一个双精度,需要将其转换为十进制.如果该值太大/太小,则结果应为decimal.MaxValue / decimal.MinValue.做这个的最好方式是什么?解决方法:我认为您意识到这是一次有损转换,因此应尽可能避免?如果您确实需要它:private static readonly double MaxDecimalAsDouble = (double) decimal.MaxValue; private static readonly double MinDecimalAsDouble = (double) decimal.MinValue;... public decimal ConvertWithCap(double in...

c#-使用正确的编码将字节数组转换为字符串【代码】

我有一些使用http://www.developerfusion.com/tools/convert/csharp-to-vb/转换为VB的C#代码private string DecodeToken (string token, string key) { byte [] buffer = new byte[0];string decoded = "";int i;if (Scramble (Convert.FromBase64String(token), key, ref buffer)){for (i=0;i<buffer.Length;i++){decoded += Convert.ToString((char)buffer[i]);}}return(decoded); }经过一点修改后,结果如下:Private ...

将访问图像OLE对象转换为C#中的原始图像字节数组【代码】

我的真正问题Invalid parameter when retrieving image from DB似乎无法完全得到答案,所以Imma一步一步尝试.在C#和MS Access 2010中使用Visual Studio2012.我的解决方案是与网络无关的应用程序. 我不确定这部分,所以在这里我的问题是如何正确地将查询中的OLE对象的图像获取到字节数组(byte [])中,因为肯定不是我正在使用以下代码进行操作.我要说的行是row [“ FOTO”].OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * ...

c#-将T []强制转换为IList是否有任何警告?【代码】

我正在实现一个包装项目数组的类,并且为了便于LINQ使用,我希望该类实现IEnumerable< T>.接口. 我第一次实现该类的“天真”尝试如下:public class Foo<T> : IEnumerable<T> {private readonly T[] _items;public Foo(T[] items) { _items = items; }public IEnumerator<T> GetEnumerator() { return _items.GetEnumerator(); } // ERRORIEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } }但是,由于该阵列仅实...

如何在C#4.5中将同步4.0转换为异步【代码】

我很难用HttpClient将下面在4.0中创建的代码转换为4.5. 根据我的理解,如果我使用异步请求,我是否应该在GUI线程本身中创建多个Web请求而不阻塞GUI. 如何在4.5中使用HttpClient将以下代码转换为异步// This is what called when button is clickedTask t3 = new Task(SpawnTask); t3.Start();//if noofthreads are less 50 then GUI is woking fine.. if number increases then takes much time for repaint.. //where as other sof...

c#-将父类动态转换为多个子类之一【代码】

因此,我对编程还不陌生,因此我试图查看是否有可能编写一种方法来检查父类的类型以找到其类型,然后针对任何结果执行相同的代码块.基本上,我只是想看看是否有一种方法可以避免在有多个不同的子类时避免长if,else if语句. 例如代替public Class Shape public Class Circle : Shape public Class Rectangle : Shape public Class Polygon : Shape ....Shape shape;if(shape.GetType() == typeof(Rectangle)) {var asRectangle = (Recta...

在C#中将类似Java的日期字符串转换为DateTime【代码】

我的日期格式如下:Tue Mar 13 12:00:00 EST 2012如何在C#.net中将它们转换为DateTime?解决方法:您可以使用TryParseExact:class Program {static void Main(string[] args){var dtString = "Tue Mar 13 12:00:00 EST 2012".ConvertTimeZone();DateTime dt;var success = DateTime.TryParseExact(dtString,"ddd MMM dd HH:mm:ss zzz yyyy",CultureInfo.InvariantCulture,DateTimeStyles.None,out dt);Console.WriteLine(success);...