肖仁辉

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  35 随笔 :: 0 文章 :: 1 评论 :: 0 引用

公告

置顶随笔 #

摘要: 1.大多数的数据类型都是值类型,值类型是存放在堆栈上的,堆栈是基于先进后出,向下填充即从高内存地址向低内存地址填充,堆栈有非常高的性能,但对于有些类型来说,使用起来还不是很灵活,因为有些类型需要在内存中存放很长时间2.string属于引用类型(有待考证,说法不一),但是不可以被继承,因为他是抽象类,一般需要new的方法都是引用类型,引用类型需要使用托管堆,托管堆与C++使用的堆是不同的,它在垃圾收...阅读全文
posted @ 2010-08-12 10:18 xrh 阅读(104) 评论(0) 编辑

2011年5月27日 #

http://kb.cnblogs.com/page/91422/
posted @ 2011-05-27 10:18 xrh 阅读(20) 评论(0) 编辑

2010年12月14日 #

代码
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
--
 Author:        ×××
-- Create date: 2010-12-14
--
 Description:    根据条件,分页数,排序,页码获取数据列表
--
 =============================================
ALTER PROCEDURE [dbo].[oask_GetRecordOfPage] 
(
    
@PageNo             INT = -1,
    
@PageSize             INT = -1,
    
@sql             nvarchar(4000)='',
    
@ordersql           nvarchar(500)='',
    
@Count                INT OUT
)
AS
DECLARE 
    
@CountSql            NVARCHAR(2000),
    
@PageCount             INT,
    
@RowCount             INT,
    
@start                INT--每页的起始位置
    @end                INT  --每页的终止位置
BEGIN 
    
SET NOCOUNT ON 
    
-- 获取页数和记录总数
    SET @CountSql = 'select @RowCount = count(1) from (' + @sql + ') as list '
    
EXEC sp_executesql  @CountSql, N'@RowCount int OUT'@RowCount OUT
    
SET @Count = @RowCount
    
    
-- 获取总页数
    IF @PageSize > 0
        
SET @PageCount = (@RowCount + @PageSize - 1)/@PageSize
    
ELSE 
        
SET @PageCount = 1
        
    
-- 页码
    SET @pageNo = @PageNo + 1
    
IF ISNULL(@pageNo0< 1 
        
SET @pageNo = 1
    
ELSE IF ISNULL(@pageNo0> @PageCount
        
SET @pageNo = @PageCount
        
    
-- 起始页和结束页
    SET @start    = (@PageNo-1)*@PageSize + 1
    
    
-- 末记录
    IF @PageSize > 0
        
SET @end= @PageNo*@PageSize
    
ELSE 
        
SET @end= @RowCount
    
    
-- 返回总页数和总记录数
    SELECT @PageCount,@RowCount

    
-- 返回当前页记录数
    SET @sql =   'select * from (' + @sql + ') as results where ROWS >=  ' + cast@start as nvarchar(10)) + ' and ROWS <=' + cast@end as nvarchar(10))+' order by '+@ordersql+' desc '
     
     
EXEC (@sql)    
END 

 

上面@sql='select *, ROW_NUMBER() OVER(order by "+ordersql+" desc ) as ROWS from Table WHERE ***'

posted @ 2010-12-14 12:01 xrh 阅读(8) 评论(0) 编辑

2010年8月25日 #

http://www.microsoft.com/downloads/zh-cn/confirmation.aspx?familyId=7e2f033b-c6b5-4565-93a5-a6048246ce28&displayLang=zh-cn

 http://kb.cnblogs.com/page/49332/ 打造优雅linq

posted @ 2010-08-25 17:26 xrh 阅读(47) 评论(0) 编辑

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections;

namespace ConsoleApplication5
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
/*定义两个泛型实体*/
            IList
<pro> student = new List<pro>();
            student.Add(
new pro() { Name = "NI", Grade = "1" });
            student.Add(
new pro() { Name = "wo", Grade = "2" });
            student.Add(
new pro() { Name = "ta", Grade = "3" });
            IList
<pro> school = new List<pro>();
            school.Add(
new pro() { Name = "wo", Grade = "2" });
            school.Add(
new pro() { Name = "you", Grade = "4" });
            
            
/*查出student在school中不存在的记录*/
            var a 
= from o in student
                    
where !(from b in school select b.Name).Contains(o.Name)
                    select o;
            
foreach (pro t in a)
            {
                Console.Write(
"{0},{1}", t.Name, t.Grade);
                Console.Write(
"\r\n");
               
            }
            Console.Write(
"隔开");
            
/*查出符合条件的记录*/
            var g 
= from c in student where c.Name=="wo" || c.Grade=="3" select c ;
            
foreach (pro v in g)
            {
                Console.Write(
"{0},{1}", v.Name, v.Grade);
                Console.Write(
"\r\n");
            }
            Console.ReadLine();
          
        }
    }

    
/*定义学生实体类*/
    
public class pro
    {
        
public string Name
        {
            
get;
            
set;
        }
        
public string Grade
        {
            
get;
            
set;
        }
    }
}

运行结果:

NI,1

ta,3

隔行wo,2

ta,3

 

posted @ 2010-08-25 17:25 xrh 阅读(67) 评论(0) 编辑

2010年8月17日 #

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

namespace ConsoleApplication12
{
    
class Program
    {
        
static void Main(string[] args)
        {
           a a1
=new b();
           Console.ReadLine();
        }
    }

    
class a
    { 
       
public a()
       {
           getv();
           setv();
       }
        
public virtual void getv(){}
        
public void setv(){}
    }
    
class b : a {

       
private static int y=0;
        
public b()
        {
            y
++;
        }

        
public override void getv()
        {
            Console.Write(y); 
        }
        
public new void setv()
        {
            Console.Write(y);
        }
    }
}

执行结果为0;

根据调试得出执行顺序:

  先执行类a的构造函数,调用getv()方法,因为getv方法被重写,所以调用的是类b的getv方法,输出0,因为此时y并没有被加值,执行setv方法时,因为只是在类b中隐藏了此方法,并没有改变掉父类方法的内容,所以仍旧调用父类方法,然后在执行类b的构造函数,实例化结束

posted @ 2010-08-17 14:51 xrh 阅读(41) 评论(0) 编辑

1.首先必须在服务器端和客户端引入System.Runtime.Remoting

2.然后编写调用类

 

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

namespace ConsoleApplication7
{
  
public  class message:MarshalByRefObject
    {
        
public delegate void MessageHandler(string msg);

        
public static event MessageHandler OnSendMessage;

        
public void SendMessage(string msg) //发送消息
        {
            
if (OnSendMessage != null)
                OnSendMessage(msg);
        }
    }
}

 

3.在编写服务器端调用类

 

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

namespace Server
{

    
class Program
    {

        
static void Main(string[] args)
        {
            Console.WriteLine(
"Host Started!");
            HttpChannel channel 
= new HttpChannel(20001);//定义个通道并指定端口
            ChannelServices.RegisterChannel(channel, false);//服务端注册通道
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ConsoleApplication7.message), "Message", WellKnownObjectMode.Singleton);//服务端注册类型,并使用Singletong激活方式
            ConsoleApplication7.message.OnSendMessage += new ConsoleApplication7.message.MessageHandler(Message_OnSendMessage);//订阅事件
            Console.Read();
        }

        
public static void Message_OnSendMessage(string msg) //
        {
            Console.WriteLine(msg);
        }

    }

}

 

4.然后在编写客户端代码:

 

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

namespace Client
{

    
class Program
    {

        
static void Main(string[] args)
        {
            Console.WriteLine(
"Client Started!");
            HttpChannel channel 
= new HttpChannel();//客户端不需要指定端口
            ChannelServices.RegisterChannel(channel, false); //注册通道
            RemotingConfiguration.RegisterWellKnownClientType(typeof(ConsoleApplication7.message), "http://localhost:20001/Message"); //注册远程处理的类型
            ConsoleApplication7.message msg = new ConsoleApplication7.message();
            
while (true//每隔2s,发送一次消息。
            {
                msg.SendMessage(
"Client time is:" + System.DateTime.Now.ToString()); //发送消息
                System.Threading.Thread.Sleep(2000);//
            }
            
//Console.ReadLine();
        }
    }
}

 

最后先调用服务器端,然后在执行客户端:

服务器端会不停的接受到从客户端发送过来的消息,并显示在运行结果上,这就是分布式处理romoting

posted @ 2010-08-17 10:56 xrh 阅读(20) 评论(0) 编辑

2010年8月12日 #

1.大多数的数据类型都是值类型,值类型是存放在堆栈上的,堆栈是基于先进后出,向下填充即从高内存地址向低内存地址填充,堆栈有非常高的性能,但对于有些类型来说,使用起来还不是很灵活,因为有些类型需要在内存中存放很长时间

2.string属于引用类型(有待考证,说法不一),但是不可以被继承,因为他是抽象类,一般需要new的方法都是引用类型,引用类型需要使用托管堆,托管堆与C++使用的堆是不同的,它在垃圾收集器的控制下工作,与传统的堆相比有很显著的性能优势,引用类型的的存储方式是在堆栈上存放地址,在堆中存放实际的对象,与堆栈不同,堆上的内存是向上分配的,所以自由空间在上面

  从上面可以看出,建立引用变量比建立值变量要复杂得多,且不能避免性能的降低,在一个引用变量的值赋予另一个相同类型的变量时,有两个引用内存中同一个对象的变量,删除其中一个引用变量时,只会删除堆栈上的地址,不会删除堆中的对象,只到程序停止或垃圾回收器回收

3.关于string是否是引用类型的一个例子

  

 

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ConsoleApplication4
{
    
/*基于string引用类型及类的考量*/
    
class Program
    {
        
static void Main(string[] args)
        {
            
/*更新字符串的值*/
            
string st = "原始字符串";
            
string s = st;
            s 
= "更新字符串";
            Console.Write(s 
+ "\r\n");
            Console.Write(st
+"\r\n");

            
/*更新类中属性的值*/
            pr pt 
= new pr();
            pr t 
= pt;
            t.y 
= 10;

            Console.Write(t.y
+"\r\n");
            Console.Write(pt.y);
            Console.ReadLine();
        }
    }
    
/**/
    
class pr
    {
        
public int y = 0;
    }
}

 

输出结果: 

我们由这个结果及代码分析可以看出,在两个实例化对象指向同一个堆时,改变其中一个值的话,另一个对象的值也会改变,但string类型中,改变其中一个的值,另一个并不会发生改变,从这点看来string是属于值类型的,这是因为string属于引用类型,但在操作上是属于值类型的

posted @ 2010-08-12 10:18 xrh 阅读(104) 评论(0) 编辑

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

namespace ConsoleApplication3
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
/*实例化派生类对象*/
            pr p 
= new pr();
            
/*调用重写的虚函数*/
            Console.Write(p.show()
+"\r\n");

            Console.Write(p.
get()+"\r\n");
            Console.Write(p.
set());
            Console.ReadLine();
        }
    }
    
/*定义抽象类*/
    
abstract class pro
    {
        
/*定义虚函数方法*/
        
public virtual string show()
        {
            
return "123";
        }

        
/*定义抽象方法*/
        
public  abstract string get();

        
public string set()
        {
            
return "145";
        }
    }

    
/*定义派生类*/
    
class pr : pro
    {
        
/*重写虚函数方法*/
        
public override string show()
        {
            
return "456";
        }
        
/*重写抽象方法*/
        
public override string get()
        {
            
return "789";
        }

        
/*隐藏基类方法*/
        
public new string set()
        {
            
return "0";
        }
    }
}
下面是相应的运行结果


 

学习总结:

  1.abstract(抽象类)可以被单继承,但不可以被实例化,抽象类内部可以定义虚函数,抽象函数等,函数可以给出定义,可以没有被实现,也可以实现;在派生类中,必须实现抽象类中没有被实现的方法

 2.new 作用是隐藏基类中同名的方法,可以在派生类中不加上,但编译时会给出警告

 3.virtual(虚方法),override(重写),是联合起来使用的,override只能对抽象方法和虚方法进行重写

 4.sealed(封闭方法、类的标志),封闭类及封闭方法不可以被重写,不可以被继承

 

 

 

posted @ 2010-08-12 09:52 xrh 阅读(87) 评论(0) 编辑

2010年8月11日 #

摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;...阅读全文
posted @ 2010-08-11 15:29 xrh 阅读(13) 评论(0) 编辑

2010年8月9日 #

摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Reflection...阅读全文
posted @ 2010-08-09 17:57 xrh 阅读(7) 评论(0) 编辑

仅列出标题  下一页