C#的编码规范中文版

C#命名规范中文版/C#编码规范中文版 最新文档地址https://github.com/hiramtan/CSharpNamingGuidelines_Chinese C#命名规范中文版/C#编码规范中文版 示例 /******************************************************************* * Description:This is a example cla... 阅读详情
1.命名规范
1. 使用 Pascal casing 定义类型和方法名
public class SomeClass
{
   public SomeMethod(){}
}
2. 使用 camel casing 定义局部变量名和方法参数
int number;
void MyMethod(int someNumber)
{}
3. 使用“I”前缀定义接口名
interface IMyInterface
{..}
4. 使用“m_”前缀定义私有成员变量
public class SomeClass
{
   private int m_Number;
}
5. 属性类使用“Attribute”为后缀
6. 异常类使用“ Exception.”为后缀
7. 方法命名采用动词短语,例如ShowDialog()
8. 带返回值的方法应该在名字中描述返回值,例如 GetObjectState()
9. 一般地,命名参数的时候加上TYPE. 这将增加代码的易读性
//正确:
public class LinkedList<KeyType,DataType>
{…}
//避免:
public class LinkedList<K,T>
{…}
10. 保持严格的缩进
  a) 使用3个空格缩进
  b) 不要使用tab键或者不标准的缩进比如1、2或者4个空格.
11. 注释的缩进和注释描述的代码同级
12. 所有的注释要拼写正确,不正确的注释意味开发混乱.
13. 使用描述性的变量名.
  a) 避免一个字符的变量名,例如“i”或者“t”。用“index”或者“temp”代替.
  b) 避免使用匈牙利命名法定义“Public”或者“protected”成员.
  c) 不要缩短单词(例如“num”代替“number”).
14. 所有的成员变量应该在顶部定义,用一个空行把它们和属性或者方法分开。
public class MyClass
{
  int m_Number;
  string m_Name;
 
  public void SomeMethod1(){}
  public void SomeMethod2(){}
}
15. 定义局部变量尽量靠近第一次使用的地方。
16. 使用有意思的命名空间,例如产品名、公司名等等
17. 避免使用类型的全称,用“using”声明代替.
18. 避免把“using”声明放在命名空间内.
19. 所有框架的命名空间在前面,自定义或者第三方的命名空间放在后面进行分组.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using MyCompmnay;
using MyControls;
20. 文件名应该反映它包含的类.
21. 总是把“{”放在新的一行.
22. 用匿名方法模拟正常方法的代码结构,排列匿名的代理
(With anonymous methods mimic the code layout of a regular method,
aligned with the anonymous delegate declaration.
a) Comply with placing an open curly brace in a new line)





2 Coding Practices
1. 使用C#预定义的类型胜于系统空间的别名

例如:
object 而不是 Object
string 而不是 String
int 而不是 Int32
2.避免多个类放在一个文件中.
3. 一个文件应该属于一个命名空间而不是多个.
4. 避免一个文件超过500行(不包括自动产生的代码).
5. 避免方法超过25行.
6. 一行不超过80个字符.
7. 不要改动自动产生的代码.
- 5 -
©2003 IDesign Inc. All rights reserved
8. If modifying machine generated code, modify the format and style to match this
coding standard.
a) Use partial classes if possible.
9. Avoid comments that explain the obvious.
10. Code should be self explanatory. Good code with readable variable and method
names should not require comments.
11. Document only operational assumptions, algorithm insights etc.
12. Avoid method-level documentation.
a) Use extensive external documentation for API documentation.
b) Use method-level comments only as tool tips for other developers.
13. Never hard-code a numeric value, always declare a constant instead.
14. Assert every assumption.
15. On average, every fifth line is an assertion.
using System.Diagnostics;
object GetObject()
{…}
object obj = GetObject();
Debug.Assert(obj != null);
16. Make only the most necessary types public, mark others as internal.
17. Always use zero-based arrays.
18. Avoid providing explicit values for enums.
19. Avoid specifying a type for an enum (like long).
20. Never use goto unless in a switch statement fall-through.
www.idesign.net August 2003
- 6 -
©2003 IDesign Inc. All rights reserved
21. Avoid function calls in Boolean conditional statements. Assign into local variables
and check on them:
bool IsEverythingOK()
{…}
//Avoid:
if(IsEverythingOK())
{…}
//Instead:
bool ok = IsEverythingOK();
if(ok)
{…}
22. Always explicitly initialize an array of reference types using a for loop.
public class MyClass
{}
MyClass[] array = new MyClass[100];
for(int index = 0; index < array.Length; index++)
{
array[index] = new MyClass();
}
23. Only catch exceptions for which you have explicit handling.
24. In a catch statement that throws an exception, always throw the original exception to
maintain stack location of original error.
catch(Exception exception)
{
MessageBox.Show(exception.Message);
throw; //Same as throw exception;
}
25. Avoid error code as methods return values.
26. Do not use the new inheritance qualifier. Use override instead.
27. Minimize code in application assemblies (EXE client assemblies), use class libraries
instead to contain business logic.
28. Never hardcode strings that will be presented to end users. Use resources instead.
29. Never hardcode strings that might change based on deployment such as connection
strings.
30. Never use unsafe code unless when using interop.
31. Always use interfaces.
a) See Chapters 1 and 3 in Programming .NET Components.
32. Avoid multiple Main() methods in a single assembly.
www.idesign.net August 2003
- 7 -
©2003 IDesign Inc. All rights reserved
33. Avoid explicit casting. Use the as operator to defensively cast to a type.
Dog dog = new GermanShepherd();
GermanShepherd shepherd = dog as GermanShepherd;
if(shepherd != null)
{…}
34. Never assume a type supports an interface. Defensively query for that interface.
SomeType obj1;
IMyInterface obj2;
/* Some code to initialize obj1, then: */
obj2 = obj1 as IMyInterface;
if(obj2 != null)
{
obj2.Method1();
}
else
{
//Handle error in expected interface
}
35. Do not provide public or protected member variables. Use properties instead.
36. Do not provide public event member variables. Use event accessors instead.
public class MySource
{
MyDelegate m_NumberChangedEvent;
public event MyDelegate NumberChangedEvent
{
add
{
m_NumberChangedEvent += value;
}
remove
{
m_NumberChangedEvent -= value;
}
}
}
37. Classes and interfaces should have at least 2:1 ratio of methods to properties.
38. Avoid interfaces with one member.
39. Strive to have 3-5 members per interface.
40. No more than 20 members per interface.
a) 12 is probably a practical limit.
41. Avoid events as interface members.
42. Avoid abstract methods, use interfaces instead.
43. Always prefer using C# generics in data structures.
44. Expose interfaces on class hierarchies.
a) See Chapter 3 in Programming .NET Components.
www.idesign.net August 2003
- 8 -
©2003 IDesign Inc. All rights reserved
45. Prefer using explicit interface implementation.
a) See Chapter 3 in Programming .NET Components.
46. Always mark public and protected methods as virtual in a non sealed class.
47. When building a long string, use StringBuilder, not string.
48. Always use a curly brace scope in an if statement, even if it conditions a single
statement.
49. With delegates as class members:
a) Copy a delegate to a local variable before publishing to avoid concurrency race
condition.
b) Always check a delegate for null before invoking it.
public class MySource
{
public event EventHandler MyEvent;
public void FireEvent()
{
EventHandler temp = MyEvent;
if(temp != null)
{
temp(this,EventArgs.Empty);
}
}
}
50. Always have a default case in a switch statement that asserts
int number = SomeMethod();
switch(number)
{
case 1:
Trace.WriteLine("Case 1:");
break;
case 2:
Trace.WriteLine("Case 2:");
break;
default:
Debug.Assert(false);
break;
}
51. Avoid providing methods on structures.
a) Parameterized constructors are encouraged.
b) Can overload operators.
52. Always provide a static constructor when providing static member variables.
53. Every line of code should be walked through in a “white box” testing manner.
54. Avoid code that relies on an assembly running from a particular location.
55. Do not use late-binding invocation when early-binding is possible.
www.idesign.net August 2003
- 9 -
©2003 IDesign Inc. All rights reserved
56. Avoid using the trinary conditional operator.
57. Do not use the this reference unless invoking another constructor from within a
constructor.
//Example of proper use of ’this’
public class MyClass
{
public MyClass(string message)
{}
public MyClass() : this("hello")
{}
}
58. Use the EventsHelper class defined in Programming .NET Components to
publish events defensively.
59. Use application logging and tracing.
60. Do not use the base word to access base class members unless you wish to resolve
a conflict with a subclasses member of the same name or when invoking a base class
constructor.
//Example of proper use of ’base’
public class Dog
{
public Dog(string name)
{}
virtual public void Bark(int howLong)
{}
}
public class GermanShepherd : Dog
{
public GermanShepherd(string name): base(name)
{}
override public void Bark(int howLong)
{
base.Bark(howLong);
}
}
61. Implement Dispose() and Finalize() methods based on the template in
Chapter 4 of Programming .NET Components.
62. Avoid casting to and from System.Object in code that uses generics.
63. Use the const directive only on natural constants such as the number of days of
week. Avoid using const on read only variables. For that, use the readonly
directive.
public class MyClass
{
public readonly int Number;
public MyClass(int someValue)
{
Number = someValue;
}
const int DaysInWeek = 7;
}
www.idesign.net August 2003
3 Project Settings and Project Structure
1. Always build your project with warning level 4


2. Treat warning as errors in Release build (note that this is not the default of VS.NET).
a) Although it is optional, this standard recommend treating warnings as errors in
debug builds as well.

3. Never suppress specific compiler warnings.

- 11 -
©2003 IDesign Inc. All rights reserved
4. Always explicitly state your supported runtime versions in the application
configuration file. See Chapter 5 in Programming .NET Components.
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.0.0"/>
<supportedRuntime version="v1.1.5000.0"/>
</startup>
</configuration>
5. Avoid explicit custom version redirection and binding to CLR assemblies.
6. Avoid explicit preprocessor definitions (#define). Use the project settings for
defining conditional compilation constants.
7. Do not put any logic inside AssemblyInfo.cs.
8. Do not put any assembly attributes in any file besides AssemblyInfo.cs.
9. Populate all fields in AssemblyInfo.cs such as company name, description, copyright
notice.
10. All assembly references should use relative path.
11. Disallow cyclic references between assemblies.
12. Avoid multi-module assemblies.
www.idesign.net August 2003
13. Always run code unchecked by default (for performance sake), but explic itly in
checked mode for prone operations.

- 12 -
©2003 IDesign Inc. All rights reserved
int CalcPower(int number,int power)
{
int result = 1;
for(int count = 1;count <= power;count++)
{
checked
{
result *= number;
}
}
return result;
}
14. Avoid tampering with exception handling using the Exception window
(Debug|Exceptions).
15. Strive to uniform version numbers on all assemblies and clients in same logical
application (typically a solution).
16. Name your VS.NET application configuration file as App.Config, and include it in
the project.
17. Avoid explicit code exclusion of method calls (#if…#endif). Use conditional
methods instead.
public class MyClass
{
[Conditional("MySpecialCondition")]
public void MyMethod()
{}
}
www.idesign.net August 2003
18. Modify VS.NET default project structure to your project standard layout, and apply
uniform structure for project folders and files.
19. Link all solution-wide information to a global shared file:


- 13 -
©2003 IDesign Inc. All rights reserved
20. Insert spaces for tabs. Use 3 spaces instead of tabs

a) Tools|Options|Text Editor|C#|Tabs
www.idesign.net August 2003
- 14 -
©2003 IDesign Inc. All rights reserved
21. Release build should contain debug symbols.

22. Always sign your assemblies, including the client applications.
23. Always sign interop assemblies with the project’s SNK file

www.idesign.net August 2003
- 15 -
©2003 IDesign Inc. All rights reserved
4 Framework Specific Guidelines
4.1 Data Access
1. Always use type-safe data sets. Avoid raw ADO.NET.
2. Always use transactions when accessing a database.
3. Always use transaction isolation level set to Serializable.
a) Requires management decision to use anything else.
4. Do not use the Server Explorer to drop connections on windows forms, ASP.NET
forms or web services. Doing so couples the presentation tier to the data tier.
5. Avoid SQL Server authentication.
a) Use Windows authentication instead.
6. Run components accessing SQL Server under separate identity from that of the
calling client.
7. Always warp your stored procedures in a high level, type safe class. Only that class
invokes the stored procedures.
8. Avoid putting any logic inside a stored procedure.
a) If there is an IF inside a stored procedure, you are doing something wrong.
4.2 ASP.NET and Web Services
1. Avoid putting code in ASPX files of ASP.NET. All code should be in the codebehind
class.
2. Code in code behind class of ASP.NET should call other components rather than
contain direct busines s logic.
3. In both ASP.NET pages and web services, wrap a session variables in a local
property. Only that property is allowed to access the session variable, and the rest of
the code uses the property, not the session variable.
4. Avoid setting to True the Auto-Postback property of server controls in ASP.NET.
5. In transactional pages or web services, always store session in SQL server.
6. Turn on Smart Navigation for ASP.NET pages.
7. Strive to provide interfaces for web services
a) See Appendix A of Programming .NET Comp onents.
8. Always provide namespace and service description for web services.
9. Always provide a description for web methods.
10. When adding a web service reference, provide meaningful name for the location.
11. Always modify client-side web service wrapper class to support cookies.
a) You have no way of knowing whether the service uses Session state or not.
www.idesign.net August 2003
- 16 -
©2003 IDesign Inc. All rights reserved
4.3 Serialization
1. Always mark non-sealed classes as Serializable.
2. Always mark un-serializable member variables as non serializable.
3. Always mark delegates on a serialized class as non-serializable.
[Serializable]
public class MyClass
{
[field:NonSerialized]
public event MyDelegate Delegate;
}
4.4 Multithreading
1. Use Synchronization Domains. See Chapter 8 in Programming .NET Components.
a) Avoid manual synchronization, because they often lead to deadlocks and race
conditions.
2. Never call outside your synchronization domain.
3. Manage asynchronous call completion on a callback method.
a) Do not wait, poll, or block for completion.
4. Always name your threads.
a) Name is traces in the debugger Threads window, making a debug session more
productive.
Thread currentThread = Thread.CurrentThread;
string threadName = "Main UI Thread";
currentThread.Name = threadName;
5. Do not call Suspend() or Resume() on a thread.
6. Do not call Thread.Sleep().
a) Thread.Sleep(0) is acceptable optimization technique to force a context
switch.
b) Thread.Sleep() is acceptable in testing or simulation code.
7. Do not call Thread.SpinWait().
8. Do not call Thread.Abort() to terminate threads.
a) Use a synchronization object instead to signal the thread to terminate. See
Chapter 8 in Programming .NET Components.
9. Avoid explicitly setting thread priority to control execution.
a) Can set thread priority based on task semantic, such as bellow normal for a
screen saver.
10. Do not read the value of the thread state property.
a) Use Thread.IsAlive() to determine whether the thread is dead.
11. Do not rely on setting the thread type to background thread for application shutdown.
a) Use a watchdog or other monitoring entity to deterministically kill threads.
12. Do not use thread local storage unless thread affinity is guaranteed.
www.idesign.net August 2003
- 17 -
©2003 IDesign Inc. All rights reserved
13. Never call Thread.Join() without checking that you are not joining your own
thread.
void WaitForThreadToDie(Thread thread)
{
Debug.Assert(Thread.CurrentThread.GetHashCode() != tread.GetHashCode());
thread.Join();
}
14. Always use the lock() statement rather than explicit Monitor manipulation.
15. Always encapsulate the lock() statement inside the object it protects.
public class MyClass
{
public void DoSomething()
{
lock(this)
{
//Do Something
}
}
}
a) Can use synchronized methods instead of writing the lock() statement
yourself.
16. Avoid fragmented locking (see Chapter 8 of Programming .NET Components).
17. Avoid using a Monitor to wait or pulse objects. Use manual or auto-reset events
instead.
18. Always release a Mutex inside a finally statement to handle exceptions.
19. Do not use volatile variables. Lock your object or fields instead to guarantee
deterministic and thread-safe access.
4.5 Remoting
1. Prefer administrative configuration to programmatic configuration.
2. Always implement IDisposable on a single call objects.
3. Always prefer TCP channel and binary format when using remoting.
a) Unless a firewall is present.
4. Always provide a null lease for a singleton object.
public class MySingleton : MarshalByRefObject
{
public override object InitializeLifetimeService()
{
return null;
}
}
5. always provide a sponsor for a client activated object. Sponsor should return initial
lease timed.
a) See Chapter 10 of Programming .NET Components.
www.idesign.net August 2003
- 18 -
©2003 IDesign Inc. All rights reserved
6. Always unregister a sponsor on client application shutdown.
7. Always put remote objects in class libraries.
8. Avoid using SoapSuds.
9. Avoid hosting in IIS.
10. Avoid using uni-directional channels.
11. Always load a remoting configuration file in Main() even if the file is empty, and
the application does not use remoting.
a) Allow the option of remoting some types later on post deployment, and
changing the application topology.
static void Main()
{
RemotingConfiguration.Configure("MyApp.exe.config");
/* Rest of Main() */
}
12. Avoid using Activator.GetObject() and
Activator.CreateiInstance() for remote objects activation. Use new
instead.
13. Always register port 0 on the client side, to allow callbacks.
14. Always elevate type filtering to full on both client and host to allow callbacks.
Host Config file:
<channels>
<channel ref="tcp" port="8005">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
<channel ref="http" port="8006">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
Client Config file:
<channels>
<channel ref="tcp" port="0">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
www.idesign.net August 2003
- 19 -
©2003 IDesign Inc. All rights reserved
4.6 Security
1. Always demand your own strong name on assemblies and components that are
private to the application, but are public (so that only you can use them).
public class PublicKeys
{
public const string MyCompany = "1234567894800000940000000602000000240000"+
"52534131000400000100010007D1FA57C4AED9F0"+
"A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C83"+
"4C99921EB23BE79AD9D5DCC1DD9AD23613210290"+
"0B723CF980957FC4E177108FC607774F29E8320E"+
"92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99"+
"285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF"+
"0FC4963D261C8A12436518206DC093344D5AD293";
}
[StrongNameIdentityPermission(SecurityAction.LinkDemand,
PublicKey = PublicKeys.MyCompany)]
public class MyClass
{…}
2. Apply encryption and security protection on application configuration files.
3. Assert unmanaged code permission, and demand appropriate permission instead.
4. On server machines deploy code-access security policy that grants only Microsoft,
ECMA and self (identified by strong name) full trust.
a) All other code is implicitly granted nothing.
5. On client machine, deploy a security policy which grants client application only the
permissions to call back the server and to potentially display user interface.
a) Client application identified by strong name.
6. Always refuse at the assembly level all permissions not required to perform task at
hand.
a) The counter a luring attack.
[assembly:UIPermission(SecurityAction.RequestRefuse,
Window=UIPermissionWindow.AllWindows)]
7. Always set the principal policy in every Main() method to Windows
public class MyClass
{
static void Main()
{
AppDomain currentDomain = Thread.GetDomain();
currentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
}
//other methods
}
8. Never assert a permission without demanding a different permission in its place. See
Chapter 12 in Programming .NET Components.
www.idesign.net August 2003
4.7 Enterprise Services
1. Do not catch exceptions in a transactional method. Use the AutoComplete
attribute.
a) See COM and .NET Component Services.
2. Do not call SetComplete(), SetAbort(), and the like. Use the
AutoComplete attribute.
[Transaction]
public class MyComponent : ServicedComponent
{
[AutoComplete]
public void MyMethod(long objectIdentifier)
{
GetState(objectIdentifier);
DoWork();
SaveState(objectIdentifier);
}
}
3. Always override CanBePooled and return true (unless you have a good reason
not to return to pool)
public class MyComponent :ServicedComponent
{
protected override bool CanBePooled()
{
return true;
}
}
4. Always call Dispose() explicitly on a pooled objects unless the component is
configured to use JITA as well.
5. Set authentication level to privacy on all applications.
6. Use Enterprise Services whenever more than one object or more than one database is
involved in a single transaction.
7. Set impersonation level on client assemblies to Identity.
8. Always set ComponentAccessControl attribute on serviced components to true
a) The default is True
9. Always add to the Marshaler role the Everyone user
[assembly: SecurityRole("Marshaler",SetEveryoneAccess = true)]
10. Apply SecureMethod attribute to all classes requiring authentication.
C#编码规范(中文pdf) C#编码规范 中文pdf C#编码规范 中文pdf C#编码规范 中文pdf C#编码规范 中文pdf 立即下载

相关推荐

C#编码规范(控件和变量)

C#编码规范(控件和变量)C#编码规范(控件和变量)C#编码规范(控件和变量)C#编码规范(控件和变量)C#编码规范(控件和变量)

C#的编码规范中文版(www.idesign.net Author: Juval Lowy) 内容

1.命名规范1. 使用 Pascal casing 定义类型和方法名public class SomeClass{public SomeMethod(){}}2.使用 camel casing 定义局部变量名和方法参数int number;void MyMethod(int someNumber){}3. 使用“I”前缀定义接口名interface IMyInterface{..}4. 使...

weixin_30662849的博客 730

c#编码规范(Microsoft DC IDesign c# coding standard)

c#编码规范(Microsoft DC IDesign c# coding standard)

C# 编码规范

从业多年,不断发现有很多团队的代码写的很随意,各种风格、命名方式都有,有用c++风格的,有用java风格的。所以本人在这里介绍下微软官方的C#编码规范,规范本身内容其实不长,但是如果能过一遍,相信对以后自己的编码会有很大帮助。注:本文不是一定适用所有人和所有团队,供大家参考。默认的就是最好的。......

catshitone的专栏 4159

C# 编码规范完整DOC版本.docx

C#语言规范(5.0版) C#语言规范主要有两个来源,即我们熟知的ECMA规范和微软的规范。 版权所有 Microsoft Corporation 1999-2012。保留所有权利。请将更正、建议及其他反馈信息发送至 csharp@http://www.wendangku.net/doc/0cec773369eae009591bec50.html

C#编码规范

通过对程序的注释方式,声明,命名规范,控件明明规则等,方便代码的交流和维护,使代码美观,阅读方便

C#的编码规范中文版(www.idesign.net Author: Juval Lowy)目录

网上找到一篇非常好的C#的编码规范,业余时间把它翻译成中文。第一次翻译。可能有些问题,希望朋友们指正。目录1命名规则 ........................................................... 3 2编码习惯 .............................................................. 43 项目设...

weixin_30640769的博客 129

C# 语言规范 版本5.0中文.pdf

C#(读作“See Sharp”)是一种简洁、现代、面向对象且类型安全的编程语言。 C# 起源于 C 语言家 族,因此,对于 C、 C++ 和 Java 程序员,可以很快熟悉这种新的语言。 C# 已经分别由 ECMA International 和 ISO/IEC 组织接受并确立了标准,它们分别是 ECMA-334 标准和 ISO/IEC 23270 标准。 Microsoft 用于 .NET Framework 的 C# 编译器就是根据这两个标准实现的。 C# 是面向对象的语言,然而 C# 进一步提供了对面向组件 (component-oriented) 编程的支持。现代软件 设计日益依赖于自包含和自描述功能包形式的软件组件。这种组件的关键在于,它们通过属性、方法和 事件来提供编程模型;它们具有提供了关于组件的声明性信息的特性;同时,它们还编入了自己的文 档。 C# 提供的语言构造直接支持这些概念,这使得 C# 语言自然而然成为创建和使用软件组件之选。 有助于构造健壮、持久的应用程序的若干 C# 特性:垃圾回收 (Garbage collection) 将自动回收不再使用 的对象所占用的内存;异常处理 (exception handling) 提供了结构化和可扩展的错误检测和恢复方法;类 型安全 (type-safe) 的语言设计则避免了读取未初始化的变量、数组索引超出边界或执行未经检查的类型 强制转换等情形。 C# 具有一个同一类型系统 (unified type system)。所有 C# 类型(包括诸如 int 和 double 之类的基元类 型)都继承于单个根类型: object。因此,所有类型都共享一组通用操作,并且任何类型的值都能够 以一致的方式进行存储、传递和操作。此外, C# 同时支持用户定义的引用类型和值类型,既允许对象 的动态分配,也允许轻量结构的内联存储。 为了确保 C# 程序和库能够以兼容的方式逐步演进, C# 的设计中充分强调了版本控制 (versioning)。许 多编程语言不太重视这一点,导致采用那些语言编写的程序常常因为其所依赖的库的更新而无法正常工 作。 C# 的设计在某些方面直接考虑到版本控制的需要,其中包括单独使用的 virtual 和 override 修 饰符、方法重载决策规则以及对显式接口成员声明的支持。 本章的其余部分将描述 C# 语言的基本特征。尽管后面的章节会更为详尽,有时甚至逻辑缜密地对规则 和例外情况进行描述,但本章的描述力求简洁明了,因而难免会牺牲完整性。这样做是为了向读者提供 关于该语言的概貌,一方面使读者能尽快上手编写程序,另一方面为阅读后续章节提供指导。

【亲测免费】 C 9.0文档 中文版

C# 9.0文档 中文版 去发现同类优质开源项目:https://gitcode.com/ 欢迎来到C# 9.0文档中文版的下载仓库!这里提供了C# 9.0官方文档的中文翻译版本,以方便国内开发者更好地学习和掌握C# 9.0的新特性和用法。 此文档详细介绍了C# 9.0的各项新特性,包括模式匹配、记录类型、初始化器、只读属性等,是您学习和深入理解C# 9.0不可多得的好资源。 文件名:C# 9.0...

gitblog_06735的博客 472

C# 编码规范 编码规范文档

本规范中的要求对所有C#相关的项目都有效。 各C#相关的项目,可以根据项目的需要,对本规范进行引用、扩充和修订,并形成项目组自己的C#编码规范的补充规定;如果项目的补充规定中有与本规范相冲突的条目,应以项目的补充规定为准,但其应用范围仅仅适用于本项目;如果项目没有特别制定自己的C#编码规范,则应完全遵循本规范。 开发人员在编写C#代码时,应该遵循本规范中的要求;而在代码评审活动中,评审负责人也应按照本规中约的要求检查C#代码的规范性。

NFT图片批量合成及稀有度计算工具

一、制作背景 -当前NFT作品制作的大多方式都是使用部件拼接的形式,然后从大量的可能性结果取优; 二、解决问题 拼接合成的组合数量十分巨大,手工合成费时费力; 合成中对各个部件的使用次数不容易控制,部位出现的概率对作品的稀有度及评分影响较大; 对于生成的作品各个部位的信息(包括来源和使用率)统计繁琐,不利于对作品的介绍中体现; 三、程序功能介绍 1、功能自定义部位稀有度批量合成NFT作品 步骤一:创建各个合成部件文件夹,将图片放到文件夹内 步骤二:软件上设置各个部件对于的图片文件夹及出现的概率 步骤二

Keeping111的博客 4638

【编码规范篇】| C#编码规范 代码规范总结,包括命名规范,代码规范 注释规范等

在我们程序员日常开发的过程中,会编写代码是一个最基本且常规的操作。而作为一名合格的软件工程师,出产物就应该具备工程的健壮性和美观性,因此编码规范是作为软件工程师的职业素养。但是就编码规范而言,可能大多数程序员都是按照自己的长久习惯进行代码编写,并没有遵循一个约定好的编码规范。所以本篇就来对C#中的编码规范做一个详细的总结整理,并对一些超级常用的做一个重点解析!对于编程而言,大多数语言的编码规范基本上是遵循一些相同的规范标准的,除去少些个语言有一些特殊用法之外。

努力前行,总会成为自己心中的那道光 4万+

从零开始理解异构算力调度:全国一体化算力算网平台实战解析

本文深入解析了异构算力调度技术在全国一体化算力算网平台中的实战应用。通过资源抽象层设计、动态感知引擎和跨云调度算法,实现AI训练任务的高效资源分配,显著提升计算效率并降低成本。特别针对GPU等异构算力的智能调度方案,为多云协同环境下的AI开发提供实用指南。

weixin_28730927的博客 334

全面的C#编码规范整理

要作为一名合格的开发者,最基本的素质就是要做到编码规范,从小我们就接受教导“字如其人”,而写代码亦是如此,良好的代码风格,彰显了个人的工作素养。而良好的代码规范,能够帮助我们进行更好的团队协作,它能方便代码的交流和维护;不会影响编码的效率,不与大众习惯冲突;使代码更美观、阅读更方便;使代码的逻辑更清晰、更易于理解。 那为什么要整理这个规范呢? 最近社区群里有在讨论C#的编码规范,而网络上也没有一些全面的规范文档,所以我就结合微软官方、Resharper和stylecop的规范,以及.

戴翔的技术博客 4115

基因家族Motif 分析

MEME

hgz2020的博客 6319

Hermes 教程 03:Skills 系统

摘要:Hermes Skills是一种自我改进机制,可将解决问题的经验保存为可复用技能文档。v0.13.0版本遵循agentskills.io开放标准,与Claude Skills互通。技能创建流程包括发现问题、创建技能文件、加载使用和优化更新四个阶段。系统提供技能检索和自维护机制(Curator),支持技能媒体路由和多种管理命令。内置技能涵盖开发调试、创意头脑风暴等场景,通过积累技能使Hermes更适应用户需求。

程序猿_三产 732

【Google C#编码规范】

Google 的C#编码规范

zhush_2005的博客 1632

为JETSON TX2开发板部署YoloV5

参考资料一:nvidia为JETSON Tx2编译的pytorch 参考资料二:Jetson软件包下载 参考资料三:Tx2安装工具的使用 参考资料四: Jetson烧录工具 参考资料五: B站下载的行人视频 一、升级TX2系统版本到最新版(JetPack4.6) 我拿到的板子的版本太低了,在工作的过程中会有很多问题,因此要先升级到最新版 下载参考资料四中的烧录工具,在Ubuntu18.04中安装,只能,必须,一定是Ubuntu18.04 安装完成后使用非root用户启动SDK Manger,登录Nvi.

贱贱的剑 5887

强烈推荐:C#编码规范手册

要作为一名合格的开发者,最基本的素质就是要做到编码规范,从小我们就接受教导“字如其人”,而写代码亦是如此,良好的代码风格,彰显了个人的工作素养。而良好的代码规范,能够帮助我们进行更好的团队协作,它能方便代码的交流和维护;不会影响编码的效率,不与大众习惯冲突;使代码更美观、阅读更方便;使代码的逻辑更清晰、更易于理解。 那为什么要整理这个规范呢? 最近社区群里有在讨论C#的编码规范,而网络上也没有一些全面的规范文档,所以我就结合微软官方、Resharper和stylecop的规范,以及曾经网路上的一些规范,整理

dotNet全栈开发 5246

SQL面试题——抖音SQL面试题 股票波峰波谷

这个题目的难度比较低,我们是用lead 和 lag 两个函数就可以搞定,也就是在一个SQL 里面同时使用多个函数,问题的考查点在于对边界的考虑。

2万+

基于投影法实现扫描文件的光学字符分割——Matlab实现

投影法是指将原图像沿着某个特定的方向进行投影,得到投影线上的像素点的个数或像素值总和,从而可以得到该方向上物体的轮廓信息。对于字符分割,我们可以将图像进行水平和垂直两个方向的投影,从而得到字符之间的分割线。在OCR技术中,字符分割是非常重要的一步骤,因为字符之间的分割对字符识别的准确性有很大的影响。通过对投影值的判断,可以求出字符之间的分割线,这里我们根据垂直方向上的投影值进行判断,选取一个阈值进行筛选即可。使用sum()函数分别计算出水平和垂直方向上的投影值,得到每一行和每一列的投影值。

TechGlide的博客 582

C#编码规范简介

本博客(http://blog.youkuaiyun.com/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!                                                                              C# 编码规范                           

学习,思考,记录,分享。 5993

ollama使用CPU安装qwen-coder模型_并在eclipse中使用ai coder插件_配置本地qwen-coder模型_ollama常用操作记录---AI大模型应用探索0002

文章摘要:作者分享了在Windows 10上安装和使用Ollama模型的过程。尝试了不同规模的qwen-coder模型(7b、1.5b和0.5b),发现7b模型响应极慢(需35分钟),而1.5b模型表现较好(3秒响应)。最终选择1.5b版本用于代码开发辅助,支持多语言自动补全。同时提到在最新版Eclipse中的AIcoder配置问题。文章重点比较了不同模型规模在CPU环境下的实际使用体验和响应速度差异。

添柴程序猿的专栏 683
上一篇: C# Coding Style Guide
下一篇: C#编码规范的几个版本
bcdliang
博客等级 码龄24年 1粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值