donet学习笔记10(c#基础)

回过头来看基础,其实觉得C#的语言和JAVA差别不大,只是存在于个别定义上的出入,整体来看都是面向对象.都是只有一个祖先类object,甚至是很多方法,属性都基本相同.所以只是对不同的部分做了一下了解.两外,我没有看索引器,事件(初看像是监听器设计模式).用到的时候再看.或则哪天想起了再看!
就我看了的而言.记录了一些与JAVA不同的东西

1.C#运行环境是再c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727下.如果要想运行CSC,那么就讲这个路径设置到环境变量的PATH中去.

2.编译的命令为:  csc 文件名.cs
  编译DLL文件的命令为:  csc /target:library 文件名.cs
  引用DLL文件的命令为:  csc /reference: 文件名.dll 主文件.cs

3.类的修饰符中,除了JAVA所有的private ,default ,protect以外还有internat 和 protect internat .其中default 的修饰和JAVA不一样.default 的类默认与internat 权限相同.default 的方法,属性与private权限相同
internat 意思是包访问权限,就是要再同一个namespace以下.
另外.C#还有两个修饰符:
        sealed:sealed修饰后的类不能被集成,像final
        partial: 可以把类放到不同的文件中.

4.类的构造方面:

    有参数的构造方法调用自身无参数的构造方法为:
        public A(int i):this() {
        }
    有参数的构造方法调用父类有参数的构造方法为:
        public A(int i):base(i) {
        }
5.关于析构,代码如下:

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

namespace  ConsoleCases
{
   
    
public class MyResource:IDisposable
    
{
        
private bool disposed = false;
        
public void Dispose() {
            Dispose(
true);
        }

   
        
public void Close() 
        
{
            Dispose(
true);
        }

         
        
~MyResource()
        
{
        Dispose(
false);
        }

        
private void Dispose(bool disposing) {
            
if(!this.disposed) {
                
if (disposing)
                
{
                    Console.WriteLine(
"调用引用对象的Dispose()方法");
                }

                Console.WriteLine(
"调用本身所使用非托管资源的代码");
                disposed 
= true;
                
if (disposing)
                
{
                    GC.SuppressFinalize(
this);
                }

            }

        }

     }

    
class Test
    
{
        
static void Main()
        
{
            MyResource mr 
= new MyResource();
            
try
            
{
                Console.WriteLine(
"调用MR做一些事情");
            }

            
finally
            
{
                mr.Dispose();
            }

            
//和上边的代码是一样的相当于在finally中释放资源
            using (MyResource mr = new MyResource())
            
{
                Console.WriteLine(
"调用MR做一些事情");
            }

        }

        

    }

}

4.关于委托,(我现在也不晓得主要会用到啥子地方!代码如下)

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

namespace  ConsoleCases
{
    
delegate void EatDelegate(String food) ;

    
    
class Party  {
        
static void eatTogether(String food, params EatDelegate[] values)
        
{
            
if (values == null)
            
{
                Console.WriteLine(
"座谈会结束");

            }

            
else
            
{
                EatDelegate eatChain 
= null;
                
foreach (EatDelegate ed in values)
                    
//就象是:eatChain = zs + ls + ww;
                    eatChain += ed;
                eatChain(food);
                Console.WriteLine();
            }

        }

        
static void Main()
        
{
            Man ZS 
= new Man("张三");
            Man WW 
= new Man("王五");
            Man LS
= new Man("李四");

            EatDelegate zs 
= new EatDelegate(ZS.eat);
            EatDelegate ls 
= new EatDelegate(LS.eat);
            EatDelegate ww 
= new EatDelegate(WW.eat);
            
           
            eatTogether(
"西瓜",zs,ls,ww);

            eatTogether(
nullnull);

        }

    }

    
class Man
    
{
        
private string name;
        
public Man(String name)
        
{
            
this.name = name;
        }

        
public void eat(String food)
        
{
            Console.WriteLine(name 
+ "" + food);
        }

    }

}


 

转载于:https://www.cnblogs.com/sorry208/articles/937564.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值