C#根据属性判断是否显示tabControls里的page页

public int Hypotest
{
    get
    {
        if (this.chkHypotest.Checked == false)
        {
            return 1;
        }
        else
        {
            if (this.rdo1.Checked)
            {
                return 3;
            }
            else if (this.rdo2.Checked)
            {
                return 4;
            }
            return 2;
        }
    }
    set
    {
        if (value <= 1)//if (value == 1) 
        {
            this.chkHypotest.Checked = false;
            tPage = this.tabPage2;

            if (this.tabControl1.TabPages.Contains(this.tabPage2))
                this.tabControl1.TabPages.Remove(this.tabPage2);
            else if (this.tabControl1.TabPages.Contains(tPage))
                this.tabControl1.TabPages.Remove(tPage);
        }
        else
        {

            if (this.tabControl1.TabPages.Count == 1)
            {
                this.tabControl1.TabPages.Add(tPage);
            }
            this.chkHypotest.Checked = true;
            if (value == 3)
            {
                this.rdo1.Checked = true;
            }
            else if (value == 4)
            {
                this.rdo2.Checked = true;
            }
        }
    }
}

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
判断一个对象集合是否包含某个属性,可以使用 LINQ 查询语句和反射来实现。具体实现步骤如下: 1. 使用 LINQ 查询语句从对象集合中筛选出包含指定属性的对象。 2. 使用反射获取对象的属性列表。 3. 遍历对象集合中的每个对象,判断对象是否包含指定属性。 4. 如果对象包含指定属性,则返回 true,否则返回 false。 以下是示例代码: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Reflection; class Program { static void Main(string[] args) { List<Person> people = new List<Person> { new Person { Name = "Alice", Age = 28 }, new Person { Name = "Bob", Age = 30 }, new Person { Name = "Charlie", Age = 35 }, }; bool hasAge = HasProperty(people, "Age"); Console.WriteLine("Has Age property: " + hasAge); bool hasGender = HasProperty(people, "Gender"); Console.WriteLine("Has Gender property: " + hasGender); Console.ReadKey(); } static bool HasProperty(IEnumerable<object> collection, string propertyName) { var type = collection.GetType().GetGenericArguments()[0]; var properties = type.GetProperties(); return properties.Any(p => p.Name == propertyName); } } class Person { public string Name { get; set; } public int Age { get; set; } } ``` 在上面的示例中,我们定义了一个包含 Name 和 Age 两个属性的 Person 类,并创建了一个包含三个 Person 对象的 List。然后,我们分别判断该 List 是否包含 Age 和 Gender 两个属性。最终输出结果为: ``` Has Age property: True Has Gender property: False ``` 可以看到,HasProperty 方法可以判断对象集合是否包含指定的属性

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值