C#: Getting lowest valued key in a bitwise Enum
-
23-09-2019 - |
문제
I have enum like this
[Flags]
public enum Key
{
None = 0,
A = 1,
B = 2,
C = 4
}
I have the following
Key k1 = Key.A | Key.B | Key.C;
I want to get the key in k1 that has the lowest value. How can I do that?
Example:
Key k1 = Key.A | Key.B | Key.C; // I want a
Key k2 = Key.B | Key.C; // I want b
Key k3 = Key.A | Key.C; // I want a
해결책
답변이 수락되었지만 코드를 통해이 작업을 수행합니다.
add.
<SharePoint:SPGridView ID=”oGrid” runat=”server” AutoGenerateColumns=”true” >
</SharePoint:SPGridView>
.
spgridview의 전자 책 :
이제 aspx.cs onload 메서드 내에서 다음을 수행합니다.
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb("yourSubSiteName"))
{
SPList list = web.Lists["list name"];
SPListItemCollection items = list.Items;
oGrid.DataSource = items.GetDataTable();
oGrid.DataBind();
}
}
}
.
이제 SharePoint에서 AXOX 파일을 빌드하고 GoTo를 GoTo하고 SharePoint 의 표준 기본 목록으로 동일한 모양과 느낌을 가진 ASPX에 목록을 볼 수 있어야합니다.
다른 팁
계정에 다음 권한이 있는지 확인하십시오.
- 디렉토리 변경 사항
- 디렉토리가 되돌리지 않음 모두
- 필터링 된 세트의 디렉토리 변경 사항을 없음
- 동기화 동기화
http : //naimmurati.wordpress..com / 2012 / 05 / 29 / 사용자 - 프로파일 동기화 - 작업 - 동기화 /
Keys key = Keys.b | Keys.c;
var lowest = Enum.GetValues(typeof(Keys))
.OfType<Keys>()
.Where(x => (x & key) != 0)
.OrderBy(x => x)
.DefaultIfEmpty((Keys)0);
Console.WriteLine(lowest);
If you have only 3 values in the enum probably the fastest and easiest is to check them one by one. For a general solution, however, you might want to try to convert the value of k1
to integer, find the largest power of 2 that divides it and convert it back to Keys enum value.
- Get a list of all the values in the enum
- Map those values to some kind of comparable data type
- Compare all the values and keep track of the lowest one
- Convert the lowest one back to the enum type
BCS를 사용하여 파일 시스템에 연결하고 SharePoint에 저장된 데이터를 표시 할 수 있습니다.
사용자가 읽고 쓸 수있는 비즈니스 연결 서비스 외부 시스템의 데이터 - 웹 서비스, 데이터베이스 및 Microsoft .NET Framework 어셈블리
다음은 방식에 도움이되는 일부 유용한 링크입니다.
SharePoint Server 2010을 사용하는 사용자 정의 비즈니스 연결 서비스 커넥터 만들기 코드 샘플 : MyFileConnector 사용자 정의 인덱싱 커넥터
The code you originally posted doesn't make sense: a+b+c aren't prefixed by a type-name, so they won't refer to the enum names they seem to be intended to refer to.
Also, if you use a bitwise AND to combine flags, the result will contain all flags on in all paramters - in this case, none.