一级目录
LINQ表达式反射type特性
LINQ表达式
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
public class Student
{
public string Name { set; get; }
public int Age { set; get; }
public string GongFu { set; get; }
public override string ToString()
{
return string.Format("name:{0},Age:{1},GongFu:{2}", Name, Age, GongFu);
}
}
public class GongFu
{
public string Name { set; get; }
public int ShangHai { set; get; }
public override string ToString()
{
return string.Format("name:{0},ShangHai:{1}", Name,ShangHai);
}
}
namespace 武学功夫
{
class Program
{
static void Main(string[] args)
{
List<Student> str = new List<Student>
{
new Student{Name="小明",Age=18,GongFu="葵花宝典" },
new Student{Name="小红",Age=28,GongFu="祥龙十八掌" },
new Student{Name="小a",Age=18,GongFu="祥龙十八掌" },
new Student{Name="小b",Age=8,GongFu="祥龙十八掌" },
new Student{Name="小c",Age=48,GongFu="祥龙十八掌" },
new Student{Name="老王",Age=113,GongFu="六脉神剑" },
new Student{Name="张三",Age=13,GongFu="葵花点穴手" },
new Student{Name="李四",Age=11,GongFu="金刚不坏" },
};
List<GongFu> fu = new List<GongFu>
{
new GongFu{Name="葵花宝典",ShangHai=86 },
new GongFu{Name="祥龙十八掌",ShangHai=70 },
new GongFu{Name="六脉神剑",ShangHai=99 },
new GongFu{Name="葵花点穴手", ShangHai=46},
new GongFu{Name="金刚不坏", ShangHai=66},
};
var str1 = from m in str
group m by m.GongFu into g
select new { count = g.Count() ,key=g.Key};
bool a= str.Any(m => m.GongFu== "祥龙十八掌");
Console.WriteLine(a);
bool b =str.All(m => m.GongFu == "祥龙十八掌");
Console.WriteLine(b);
foreach (var item in str1)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}
反射type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace 反射和特性type
{
class Program
{
static void Main(string[] args) {
Myclass my = new Myclass();
Assembly assem = my.GetType().Assembly;
Console.WriteLine(assem.FullName);
Type[] types= assem.GetTypes();
foreach(Type ty in types)
{
Console.WriteLine(ty);
}
Console.ReadKey();
}
}
}
特性
#define Istext
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
特性
{
[AttributeUsage(AttributeTargets.Class)]
sealed class MytextAttribute : System.Attribute
{
public string A { set; get; }
public int Id { set; get; }
public MytextAttribute(string str)
{
this.A = str;
}
}
}
namespace 特性
{
[Mytext("简单的特性类",Id =50)]
class Program
{
[Obsolete("dd",true)]
static void OldMethod()
{
Console.WriteLine("OldMethod");
}
static void NewMethod()
{
Console.WriteLine("NewMethod");
}
[Conditional("Istext")]
static void text1()
{
Console.WriteLine("text1");
}
static void text2()
{
Console.WriteLine("text2");
}
[DebuggerStepThrough]
static void PrintOut(string str,[CallerFilePath]string filename=" ",
[CallerLineNumber] int linenumber=0,[CallerMemberName] string mathodName="")
{
Console.WriteLine(str);
Console.WriteLine(filename);
Console.WriteLine(linenumber);
Console.WriteLine(mathodName);
}
static void Main(string[] args) {
Type type = typeof(Program);
object[] array= type.GetCustomAttributes(false);
MytextAttribute mytext= array[0] as MytextAttribute;
Console.WriteLine(mytext.A);
Console.WriteLine(mytext.Id);
Console.ReadKey();
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-65338.html