[英]Cannot implicitly convert type 'string' to 'byte' in c#
[英]Cannot implicitly convert type 'byte[]' to 'byte?[]' in C#
我給定的代碼有類型轉換錯誤:
byte?[] AibAttachment = null;
MemoryStream target = new MemoryStream();
file.InputStream.CopyTo(target);
AibAttachment = target.ToArray();
在上面的代碼中 AibAttachment = target.ToArray(); 這一行拋出了一個錯誤,比如“不能隱式地將‘字節[]’轉換為‘字節?[]’”
請幫我解決這個問題。
也許你可以做這樣的事情:
AibAttachment = Array.ConvertAll(target.ToArray(), i => (byte?)i);
Linq的另一個答案:
byte[] original = null; // something
byte?[] AibAttachment = original.Select(a => (byte?) a).ToArray();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.