Yoda Conditions
Using if(constant == variable) instead of if(variable == constant), like if(4 == foo). Because it's like saying "if blue is the sky" or "if tall is the man".I will have to add that to my guidelines.
Yoda Conditions
Using if(constant == variable) instead of if(variable == constant), like if(4 == foo). Because it's like saying "if blue is the sky" or "if tall is the man".I will have to add that to my guidelines.
void Main() {
// Create a new Circle but cast it as a Shape
Shape obj = new Circle();
// Call the virtual method
Console.WriteLine(obj.WhoAmI());
// Call the extension method
Console.WriteLine(obj.WhoAmIEx());
}
public class Shape {
public virtual string WhoAmI() {
return "Virtual Shape";
}
}
public class Circle : Shape {
public override string WhoAmI() {
return "Overriden Circle";
}
}
public static class Extensions {
public static string WhoAmIEx(this Shape obj) {
return "Shape Extension";
}
public static string WhoAmIEx(this Circle obj) {
return "Circle Extension";
}
}Overriden Circle Shape Extension
public Image ImagePath(string path) {
imagePath = path;
return this;
}
You could just write:
public this ImagePath(string path) {
imagePath = path;
}
// Create a basic users table.
DbTableBuilder table = new DbTableBuilder(dbType, "USERS", setupLog);
table.AddKeyColumn("userid");
table.AddCharColumn("username", 255);
table.AddCharColumn("password", 50);
table.AddCharColumn("email", 100);
table.AddCharColumn("name", 100);
table.CreateTable(connection);
// Create an index on the username.
index = new DbIndexStatement("IDX_USERS_NAME", "USERS", "username");
index.CreateIndex(connection);
using (SqlCommand cmd = sqlConnection.CreateCommand()) {
cmd.CommandText = "CREATE INDEX index_name ON table_name (column_name)";
connection.Open();
cmd.BeginExecuteNonQuery();
}
SELECT spid FROM MASTER.dbo.sysprocesses WHERE program_name = N'SQLAgent - Generic Refresher'