| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 916 人关注过本帖
标题:C#的类不懂
只看楼主 加入收藏
boking134
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-20
收藏
 问题点数:0 回复次数:6 
C#的类不懂
我是新手,我看了C#的一些教程,可是我不太懂类,有没有可以给我讲解下~
搜索更多相关主题的帖子: 教程 
2011-08-21 10:20
一氧化碳
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:132
专家分:335
注 册:2007-8-13
收藏
得分:0 
看书吧

2011-08-22 14:23
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
这个好说,变量,构造函数和成员函数,还有注意静态与非静态的区别就好!

   唯实惟新 至诚致志
2011-08-22 16:24
artai
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-8-22
收藏
得分:0 
給你一個最簡單的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQ_EX1
{
    class Program
    {
        static void Main(string[] args)
        {
              // CREATE ARRAY TO FOR TESTING
              Person[] people = {
              new Person { Name="Allen Frances", Age=11},
              new Person { Name="Burke Madison", Age=50},
              new Person { Name="Connor Morgan", Age=59},
              new Person { Name="David Charles", Age=33},
              new Person { Name="Everett Frank", Age=16}
            };

            foreach (var newPeople in people)
            {
                Console.WriteLine("{0} is {1} years old",
                   newPeople.Name,
                   newPeople.Age
                   );
            }

            Console.ReadLine();
        }
    }

    /*================================
    *
    *           NEW DATA OBJECT CLASS PERSON FOR SYSTEM TEST
    *
   ================================ */
    public class Person
    {
        public string Name{get; set;}
        public int Age{get; set;}
    }
}

[ 本帖最后由 artai 于 2011-8-22 16:39 编辑 ]
2011-08-22 16:32
artai
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-8-22
收藏
得分:0 
再來,為它加點意義:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQ_EX1
{
    class Program
    {
        static void Main(string[] args)
        {
              // CREATE ARRAY TO FOR TESTING
              PersonB[] people = {
              new PersonB { Name="Allen Frances", Age=11},
              new PersonB { Name="Burke Madison", Age=50},
              new PersonB { Name="Connor Morgan", Age=59},
              new PersonB { Name="David Charles", Age=33},
              new PersonB { Name="Everett Frank", Age=16}
            };

            // USE LINQ TO CHECK THE ITEMS WHICH NEEDED TO UPDATE
            var query = from myPerson in people
                        where myPerson.Age == 11
                        select myPerson;

            // UPDATE OR ADD NEW VALUE INTO THAT OBJECT
            foreach (var item in query)
                item.otherValue = "<<<Allen FUXK>>>";


            foreach (var newPeople in people)
            {
                Console.WriteLine("{0} is {1} years old, and their new value is {2} ...",
                   newPeople.Name,
                   newPeople.Age,
                   newPeople.otherValue
                   );
            }

            Console.ReadLine();
        }
    }

    /*================================
    *
    *           NEW DATA OBJECT CLASS PERSON FOR SYSTEM TEST
    *
   ================================ */
    public class Person
    {
        public string Name{get; set;}
        public int Age{get; set;}
    }

    public class PersonB: Person
    {
        public string otherValue{get; set;}
    }
}

Object在C#裡很好用! 您看完每個用法, 最好也給他多點練習!
2011-08-22 16:39
lip0605
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-8-25
收藏
得分:0 
看看谭浩强的C++那本书,不错。推荐给你
2011-08-25 16:54
lys120955350
Rank: 1
等 级:新手上路
帖 子:7
专家分:5
注 册:2010-10-17
收藏
得分:0 
新手上路 你就不能换点新鲜点的
2011-08-26 17:13
快速回复:C#的类不懂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019334 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved