如何在c#中将布尔值转换为Bit [英] How to convert Boolean value to Bit in c#

查看:715
本文介绍了如何在c#中将布尔值转换为Bit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在从数据库中检索位值并使用服务将其发送到表中。问题是c#没有位类型。所以我必须将其检索为boolean或int。



这会影响我绑定数据的结果表。



位将显示为复选框,其中布尔值在表格中显示为true false。我想显示为复选框。 table是客户端,正在使用javascript ajax调用绑定。

Hello ,
I am retrieving bit value from database and sending it to a table using service. problem is that c# dosen't have bit type. so i have to either retrieve it as boolean or int.

And this is affecting the result table to which i am binding the data.

bit will be shown as checkbox where as Boolean is shown as true false in table. i want to show as checkbox. table is client side and is being bind using javascript ajax call.

推荐答案

听起来你的行为错误,相信你真的在数据库中存储了位值 。我想看看。实际上,比特类型本身并未使用,它们可能相当无用。但是逻辑上需要1位的布尔值可以打包在真正占用一位的结构中,只有在你有大量这样的值时才有意义。



在.NET中,请查看以下类型: https:/ /msdn.microsoft.com/en-us/library/system.collections.bitarray%28v=vs.110%29.aspx [ ^ ]。



此外,您需要知道如何访问位。请参阅: https://msdn.microsoft.com/en-us/library/6a71f45d.aspx [ ^ ]。



此CodeProject文章也可以提供帮助:了解按位运算符的工作原理(C#和VB.NET示例) [ ^ ]。



我不是说它将帮助您直接解决当前的问题。这只是一些有用的东西。但它应该帮助你克服你的误解。如果您需要进一步的帮助,请澄清。



-SA
It sounds like you act in a wrong believe that you really store "bit values" in your database. I would like to see it. In reality, "bit types" are not used per se, they would probably pretty useless. But Boolean values, logically requiring 1 bit, can be packed in structures where they really take one bit, which only makes sense if you have a bulk of such values.

In .NET, look at this type: https://msdn.microsoft.com/en-us/library/system.collections.bitarray%28v=vs.110%29.aspx[^].

Also, you need to know how bits are accessed. Please see: https://msdn.microsoft.com/en-us/library/6a71f45d.aspx[^].

This CodeProject article can also be helpful: Understand how bitwise operators work (C# and VB.NET examples)[^].

I'm not saying it will help you to solve your present problem directly. It's just something useful to understand. But it should help you to overcome your misconception. If you need further help, please clarify.

—SA


这篇关于如何在c#中将布尔值转换为Bit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆