C#问题
1.结构体里面是否可以有属性?
可以有属性。实测代码以及截图。
In C#, we can use the following statement to convert a string s to an integer num 124
A.int num = Convert.ToInt32(s);
B.int nym = Int32.Parse(s);
C.int num = s.ToInt();(不可以)
D.int num = int.Parse(s);(测试可以过)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Fraction
{
public struct StructTest
{
private int x;
public int X
{
get { return x; }
set { x = value; }
}
public StructTest(int _x)
{
x = _x;
}
}
class Program
{
static void Main(string[] args)
{
StructTest str = new StructTest();
str.X = ;
Console.WriteLine(str.X);
string s = "";
int num1 = Convert.ToInt32(s);
int num2 = Int32.Parse(s);
//int num3 = s.ToInt();
int num4 = int.Parse(s);
Console.WriteLine("num1="+num1);
Console.WriteLine("num2="+num2);
//Console.WriteLine(num3);
Console.WriteLine("num4="+num4);
Console.Read();
}
}
}
Property 可声明在 class, struct, interface里!
使用属性的好处:
允许只读或者只写字段;
可以在访问时验证字段;
接口和实现的数据可以不同;
替换接口中的数据。
2.参数传递的方式:按值传递、按引用传递。没有按位置传递、没有按名称传递。
3.LINQ查询:LINQ to Object, LINQ to XML, LINQ to ADO.NET 包括两种独立的技术: LINQ to DataSet 和 LINQ to SQL
对于LINQ to Object可以查询数组等里面的数据;
对于LINQ to SQL可以查询SQL能够查询的表中的数据;
对于LINQ to XML可以查询XML文档的标签等;
对于LINQ to DataSet可以查询DataSet中的数据;
3.委托的形式
f = delegate(int x){return x + 1;};
f = x => x+1;
测试代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Lambda
{
class Program
{
static void Main(string[] args)
{
int sum = ;
Func<int, int> f1 = x => * x + ;
Func<int, int, bool> f2 = (x, y) => x > y;
Func<string, int, string> f3 = (x, y) => x.Substring(y);
Func<int, int> f4 = (x) => sum += x;
Action a1 = () => { System.Console.WriteLine("HelloWorld"); };
Action <int> a2 = (x) => { System.Console.WriteLine(x); };
Action <bool> a3 = (x) => { System.Console.WriteLine(x); };
Action<string> a4 = (x) => { System.Console.WriteLine(x); }; for (int i = ; i <= ; i++ )
{
f4(i);
}
a2(sum);
a1();
a2(f1());
a3(f2(, ));
a4(f3("Zhengpengfei", ));
System.Console.Read();
}
}
}
4.内嵌类型可以是类、结构、结构体、枚举、委托
具体见PPT
5.类与结构体、类与接口、重载(overloading)与重写(overriding)、虚方法与抽象方法、托管代码与非托管代码
6.Constants can be declared static (True)
在C#中const与static不能同时修饰变量;
7.装箱boxing:值类型转换为引用类型;
拆箱unboxing:引用类型转为值类型。
8.An interface member is implemented or _inherited__from a base class
接口的成员要么自己定义要么继承自父类。
接口不能包含常量、字段、操作符、构造函数、析构函数、任何静态成员、方法的实现;
9.What is the difference between private assembly and public assembly?
private assembly只能被一个应用程序使用、保存在应用程序目录中、不要求强命名、无法签名;
public assembly可以被所用应用程序使用、保存在全局程序集中、必须有一个强命名、可以签名
另外强命名包括四个部分:Assembly的命名、Assembly的版本号、Assembly的文化属性、Assembly的公钥。
10.Which of the following are correct ways to pass a parameter to a attribute?
1) By value 2)by reference 3)by position 4)by name
A 1 ,2 B 3,4 C 1,2,3,4 D1,2,3
随机推荐
- 介绍开源的.net通信框架NetworkComms框架 源码分析(七)ProtobufSerializer
原文网址: http://www.cnblogs.com/csdev Networkcomms 是一款C# 语言编写的TCP/UDP通信框架 作者是英国人 以前是收费的 目前作者已经开源 许可是 ...
- c#重点[封装,继承,多肽]
面向对象的语言三大特点:封装.继承.多态 Ⅰ.封装:是把类的内部隐藏起来,以防止外部世界看见的一个面向对象的概念,通过关键字去控制变量,方法的访问权限. 1).访问修饰符: Ⅱ.继承: eg:我们建一 ...
- spring笔记1 spring MVC的基础知识1
1,spring MVC的流程 优秀的展现层框架-Spring MVC,它最出彩的地方是注解驱动和支持REST风格的url. 流程编号 完成的主要任务 补充 1 用户访问web页面,发送一个htt ...
- 【Java每日一题】20161201
20161130问题解析请点击今日问题下方的"[Java每日一题]20161201"查看 package Dec2016; public class Ques1201 { publ ...
- mysql 增、删、改、查 、函数、执行次序
这些是最基础的部分,若果这些不能满足你的需求,可以到http://www.w3school.com.cn中查询 增删改: 增 insert into<表名>(<列名列表>(如果 ...
- Java经典实例:在正则表达式中控制大小写
默认是:区分大小写的: 传递标志参数:Pattern.CASE_INSENSITIVE,以说明匹配时忽略大小写:如果你的代码运行在不同的地区那么你应该再添加一个Pattern.UNICODE_CASE ...
- wso2esb之代理服务 Proxy Services
代理服务 顾名思义,代理服务充当了WSO2 ESB服务的代理,通常是一个已经存在的服务端点,代理服务可以使用不同的传输方式. 客户可以直接发送请求代理服务的ESB,客户看到服务代理. 运行示例 配置W ...
- Nginx学习随笔
题外话 第一份工作中项目中有DBA和运维,所以平时也只关注开发部分,对数据库和服务器关注比较少,记得那时有用户反馈网站很慢,老大让我联系运维看看是不是服务器的问题,那时也不知道Nginx是个什么东西. ...
- CentOS系统Kernel panic - not syncing: Attempted to kill init
结果启动虚拟机出现如下问题: Kernel panic - not syncing: Attempted to kill init 解决方法: 系统启动的时候,按下'e'键进入grub编辑界面 ...
- 高性能javascript学习笔记系列(3) -DOM编程
参考 高性能javascript 文档对象模型(DOM)是独立于语言的,用于操作XML和HTML文档的程序接口API,在浏览器中主要通过DOM提供的API与HTML进行交互,浏览器通常会把DOM和ja ...