string useOfTrimEnd1= “Hello World !”.TrimEnd(‘!’); OUTPUT: Hello World string useOfTrimEnd2= “Hello World !!!!!!”.TrimEnd(‘!’); OUTPUT: Hello World Definition from Microsoft.com: TrimEnd(Char) Removes all the trailing occurrences of a character from the current string. TrimEnd() Removes all the trailing white-space characters from the current string. TrimEnd(Char[]) Removes all the trailing occurrences of a set of characters specified […]
Tag: code
How to add default value for Entity Framework migrations for DateTime and Bool
Just add defaultValue parameter in CreateTable method for property: public partial class TestSimpleEntity : DbMigration { public override void Up() { CreateTable( “dbo.SimpleEntities”, c => new { id = c.Long(nullable: false, identity: true), name = c.String(), deleted = c.Boolean(nullable: false, defaultValue: true), }) .PrimaryKey(t => t.id); } public override void Down() { DropTable(“dbo.SimpleEntities”); } } After that, run update-database -verbose command, […]
How to put text inside MVC Razor code block
The contents of a code block ({ … }) are expected to be code or markup (tags), not plain text. If you want to put text directly in a code block, you have three choices: Wrap it in any HTML tag Wrap it in the special Razor <text> tag, which will just render the text without the […]
How to lock the ciritical code part in C#
According to Microsoft: The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released. The lock keyword calls Enter at the start of the block and Exit at the end of the block. lock keyword actually […]
How to run code if not in Debug Mode in C#
Sometimes you want to run your code only when it is not in debug mode. You can use #IF DEBUG code block for this purpose #if DEBUG LogMail(“It is in debug mode, only add a log record.”) #else SendMail(“It is not in debug mode, so you can send e-mail.”) #endif
mysql_connect() in PHP 7
After upgrading to PHP 7.x from PHP 5.x, you start getting error of “Call to undefined”. This is because mysql_* functions are completely removed from PHP 7, it was get deprecated in PHP 5.5 but now it is completely removed. The older mysql function are removed due to following reasons: Not work on Object Oriented […]
Using Code Blocks, Mixing Text & C# Code and Comments in Asp.NET MVC Razor
In Razor you can create blocks of code nearly anywhere using @{ }. A block of code doesn’t emit anything into the output, but you can use the block to manipulate a model, declare variables, and set local properties on a view. Be extremely careful about having too much code in a view, however, because […]
Important Tips To Write Clean Code In C# from Debendra Dash
To develop reusable, reliable, readable, well-structured, and maintainable application, we must follow the coding standard. There are several coding practices in the software industry. None of them are good or bad but the main thing is that whatever approach we follow, we should make sure that everyone should follow the same standard.
Devexpress ASPxGridview Column Grouping in Code
The following code shows how to group by two columns (“Country” and “City”).
Fire Combobox SelectedIndexChanged with button code-behind
myComboBox_SelectedIndexChanged(myComboBox, new EventArgs()); // or (null, null)