C#共通特性

3240 ワード

1、     ID
.NET        ID, :ID,ClientID UniqueID
ID            ,         ID          ;
ClientID          HTML         ID,          ,ASP.NET                      ClientID  。ClientID           ID          UniqueID     。    ID             (_)   ;
UniqueID          、           ,           HTML         name  ;

2.HttpContext.Current
var context = HttpContext.Current;

3.    
1)        get set,         private    
2)Attributes          ,                 
public class Point
{
    public int X { get; set; }//     
    public int Y { get; private set; }//          
    public int T { get; set; }
}

4.         
class Test_45
{
    Point p = new Point { X = 23, T =2};//               
    //       
    List<Point> PoList = new List<Point> 
    {
    new Point {X =2,T =3},
    new Point {X =4,T=2},
    new Point {X=23,T =90}
    };
}

5.    
           ,          ,             。               !                。
// Point        GetZeroPoint
public static  Point GetZeroPoint(this Point p)
{
    return new Point { X = 0, T = 0 };
}

6.Lambda   
 //Lambda             ,         
//(int x)=>{return x+1;}
//(int x)=>x+1;
//x=>x+1;
//(x,y)=>x+y;
public void TestLambda()
{
    List<Point> pList = new List<Point> 
    {
        new Point {X =2,T =3},
        new Point {X =4,T=1}
    };
    List<Point> ppList = new List<Point>();
    ppList = pList.FindAll(p => p.X > 2 && p.T < 3);
}

7.  

8.    
string[] words = sentence.Split(' ');
string reversed = words.Aggregate((workingSentence, next) => next + " " + workingSentence);
bool b = words.All(w => w.Length > 5);
bool b2 = words.Any(w => w.Length > 10);

9.      
var num = 5;
var a = new[] { 2, 5, 6, 7 };
var anon = new { Name = "Terry", Age = 34 };
var list = new List<int>();

10.   
string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };
public System.Collections.IEnumerator GetEnumerator()
{
    for (int i = 0; i < m_Days.Length; i++)
    {
        yield return m_Days[i];
    }
}

11.LINQ     
int[] items = new int[] { 1, 2, 3, 4, 5 };
IEnumerable<int> ints = from item in items
                        where item > 2.5
                        select item;
foreach (var p in ints)
{
    Console.WriteLine(p);
} 

12.    
                      ,                            ,                。
var card = from c3 in cards
            where c3.ID > 13
            //select c3;
            select new {MyID= c3.ID,MyPassword= c3.Password };
foreach (var item in card )
{
    Console.WriteLine(item.MyID.ToString()+"---"+item.MyPassword );
}