百钱百鸡 LINQ取得现在时间 Trim的解释

本文探讨了经典的百钱买百鸡问题,并提供了一种编程解决方案。此外,还介绍了如何利用LINQ来获取服务器当前时间的方法。
ExpandedBlockStart.gif代码
百钱百鸡

意思是说:  
  去菜市场买鸡,大鸡3元一只,小鸡1元三只,求怎么才能用100元刚好买100只鸡,要求用任意程序实现!
求达人代码

int y=100/3;
  
for(int i=1;i<y;i++)
  {
  
int a = 100 - 3 * i;
  
if (a * 3 + i == 100)
  {
  Console.WriteLine(
"大:"+i+"金额"+i*3+" 小:"+3*a+"金额"+a);
  Console.ReadLine();
  }
  } 



使用linq时怎么获得服务器时间
var obj 
= (from d in db.DEF_Product where CredateDate>Getdate() select d);
            
return obj.ToList<Product, DEF_Product>(Populate);
  [Function(Name 
= "GetDate", IsComposable = true)]
        
public DateTime GetDate()
        {
            MethodInfo mi 
= MethodBase.GetCurrentMethod() as MethodInfo;
            
return (DateTime)this.ExecuteMethodCall(this, mi, new object[] { }).ReturnValue;

        }

        [Function(Name 
= "Reverse", IsComposable = true)]
        
public string Reverse(string str)
        {
            MethodInfo mi 
= MethodBase.GetCurrentMethod() as MethodInfo;
            
return (string)this.ExecuteMethodCall(this, mi,
            
new object[] { str }).ReturnValue;
        }



String.Trim()方法会去除字符串两端,不仅仅是空格字符,它总共能去除25种字符: 
(
'\t''\n''\v''\f''\r'' ''\x0085''\x00a0'' '' '' '' '' '' '' '' '' '' '' '' ''?''\u2028''\u2029'' ''?')


如果你想保留其中的一个或多个(例如\t制表符,\n换行符,\r回车符等),请慎用Trim方法。

请注意,Trim删除的过程为从外到内,直到碰到一个非空白的字符为止,所以不管前后有多少个连续的空白字符都会被删除掉。

果想去除字符串两端其他任意字符,可以考虑Trim他的重载兄弟:String.Trim(Char[])

 

转载于:https://www.cnblogs.com/z2002m/archive/2010/12/21/1912290.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值