退伍军人请原谅我提出愚蠢的问题.我知道具有私有构造函数的类会阻止实例创建.
class InterestRate
{
// static constructor
static InterestRate()
{
}
//private constructor
private InterestRate()
{
}
// private overloaded constructor
private InterestRate(double d1,double d2)
{
}
// overloaded constructor
public InterestRate(int a,int b)
{
Console.WriteLine("a={0},b={0}",a,b);
}
}
static void Main()
{
//As it is private constructor invokation i can not create a instance
InterestRate firstInstance=new InterestRate();
// non-private overloaded constructor allow me to craete instance
InterestRate r=new InterestRate(10,10);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果具有私有构造函数的类阻止实例创建,为什么该类支持具有非私有构造函数?
因为我是C#的新手,只是想知道,我可以像CQuery一样在C#中执行函数链接吗?
示例jQuery:
$("#gview tbody tr")
.not(":first,:last")
.filter(":odd")
.addClass("someclass")
.css("border","solid 1px grey");
Run Code Online (Sandbox Code Playgroud)
注意:我不是指客户端脚本.我唯一关心的是C#中是否可以进行函数链接
我如何保护我的IL不受逆向工程的影响?任何Obsfuscator工具都可用?它会提供最大的安全性吗?
来自XML文档
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<Products>
<Product ProductId="1001" ProductName="ProductA" ProductPrice="123.45" />
<Product ProductId="1002" ProductName="ProductB" ProductPrice="100.45" />
</Products>
....
Run Code Online (Sandbox Code Playgroud)
如何使用"Sum"来查找总和 ProductPrice?
当我使用
XDocument doc = XDocument.Load("Product.xml");
var sum =
from tot in (int)doc.Descendants("Product").
Attributes("ProductPrice").Sum()
select tot;
Run Code Online (Sandbox Code Playgroud)
我收到错误:"无法将类型system.xml.linq.xmlattribute转换为int".
是否可以在ForEach扩展方法中选择多个entiies?
(即)
部分代码给出
DataTableA.AsEnumerable().ToList().
ForEach(x=>
{
x.SetField<string>("Name","Jon Skeet"),
x.SetField<string>("msg","welcome")
});
Run Code Online (Sandbox Code Playgroud)
当我在ForEach中应用多个选择时
x=>
{
x.SetField<string>("Name","Jon Skeet"),
x.SetField<string>("msg","welcome")
}
Run Code Online (Sandbox Code Playgroud)
我无法完成声明.请帮助.
从我理解的MSDN文档(我不确定,我完全理解):
静态成员只能对静态数据进行操作并调用静态方法
定义类.
class Test
{
static int i;
public static void StaticDemo()
{
int v;
i=10;
v=10*i;
Console.WriteLine("The value of i={0}",v);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,StaticDemo()方法中的声明int v 不是静态字段.那怎么操作v = 10*我工作?
考虑以下继承:
abstract class Employee
{
private string empID;
private string empName;
}
class SoftwareDeveloper : Employee
{
............
}
class MarketingPerson : Employee
{
...........
}
static void Main()
{
Employee Jaffer = new SoftwareDeveloper();
Employee George = new MarketingPerson();
// Ok because of is-a relationship
LayOff(Jaffer);
// Ok because of is-a relationship
LayOff(George);
object Leo = new MarketingPerson();
// Error because downcast is required as (MarketingPerson) Leo
LayOff(Leo);
}
static bool LayOff(Employee emp)
{
// some Business Logic
return …Run Code Online (Sandbox Code Playgroud) 由于封装和抽象都与信息隐藏有关,我是否可以将封装理解为抽象的子集?
由于Func <>委托不采取"无效",我怎么能在C#3.0中解决以下问题
Func<int, int, void> delg = (a, b) => { Console.WriteLine( a + b); };
Run Code Online (Sandbox Code Playgroud) 假设我们正在创建一个System.Array
Array _twoD = Array.CreateInstance(typeof(string), 2,2);
_twoD.SetValue("Harrish", 0, 0);
_twoD.SetValue("Goel", 0, 1);
_twoD.SetValue("Prakash", 1, 0);
_twoD.SetValue("Manish", 1, 1);
foreach (string str in _twoD)
{
Console.WriteLine(str);
}
Run Code Online (Sandbox Code Playgroud)
枚举器如何自动迭代[0,0] [0,1],[1,0],[1,1]?
[对于单维数组,很容易理解,2D和3D内部会发生什么?]
我们可以使用System.Array创建Jagged Style数组吗?
考虑这个例子:
IList<string> _lstColl = new[] { "Alex", "Sam", "Gates", "Riaz" };
Run Code Online (Sandbox Code Playgroud)
我可以将它初始化为:
string[] _stringBag = new[] { "Alex", "Sam", "Gates", "Riaz" };
Run Code Online (Sandbox Code Playgroud)
在这里使用接口有什么好处?
请考虑以下嵌套类型:
public class Book
{
private class Chapter
{
}
}
Run Code Online (Sandbox Code Playgroud)
由于章节类型是由书籍控制的,它是一种构成方式还是在这里思考构图是一个错误的假设?
我不确定,所以要理解这一点,我提出了这个问题.