Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: C#

C#

Constructors and Its Types in C#

- 25.03.20 | 29.03.20 - ErcanOPAK comment on Constructors and Its Types in C#

Constructor is a special method of the class that is automatically invoked when an instance of the class is created is called a constructor. The main use of constructors is to initialize the private fields of the class while creating an instance for the class. When you have not created a constructor in the class, the compiler […]

Read More
C#

What does the word ‘new’ mean exactly in C#?

- 22.03.20 | 29.03.20 - ErcanOPAK comment on What does the word ‘new’ mean exactly in C#?

In C# (and many other languages) you will find that you use new often as it is fundamental to using types and classes. The new keyword does pretty much what it says: it will create a new instance of a class or type, assigning it a location in memory. Let me try and illustrate this. Company company; Here […]

Read More
C#

Determine If string contains more than 1 value in C#

- 16.03.20 | 29.03.20 - ErcanOPAK comment on Determine If string contains more than 1 value in C#

Let’s say you have a condition like that: if ((myString.Contains(“Value1”) && (myString.Contains(“Value2”)) && (myString.Contains(“Value3”))) { … } Basically, you want to check if all of your values are contained in the string . Fortunately (with the help of LINQ), this can by translated almost literally into C#: var values = new String[] {“Value1”, “Value2”, “Value3”}; if […]

Read More
ASP.Net WebForms / C#

How to calculate the sum of the datatable column in asp.net?

- 14.03.20 | 14.04.20 - ErcanOPAK comment on How to calculate the sum of the datatable column in asp.net?

To calculate the sum of a column in a DataTable use the DataTable.Compute method. DataTable dt; … int sumValue; sumValue = dt.Compute(“Sum(TheSumColumn)”, string.Empty);

Read More
C#

How to run code if not in Debug Mode in C#

- 11.03.20 - ErcanOPAK comment on 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

Read More
C#

How to select distinct rows in a datatable in C#

- 10.03.20 | 24.03.26 - ErcanOPAK comment on How to select distinct rows in a datatable in C#

The Scenario: You’ve loaded a massive DataTable from an Excel file, a CSV, or a legacy database. Now you realize it contains duplicate entries, and you need a unique list based on one or more columns—without writing complex foreach loops or heavy LINQ queries. The Pro Solution: The built-in DefaultView.ToTable() method is the most efficient […]

Read More
ASP.Net MVC / ASP.Net WebForms / C#

How to use Stopwatch in C#

- 22.12.19 - ErcanOPAK comment on How to use Stopwatch in C#

The Stopwatch object is often used to measure how long things take. One quick thing to remember here is that it will take the time for everything you do between starting and stopping it, so make sure you only put the actual code you want to time between those.

Read More
ASP.Net WebForms / C#

How to access session variable in App_Code class file?

- 05.12.19 | 22.12.19 - ErcanOPAK comment on How to access session variable in App_Code class file?

string MySessionValue = System.Web.HttpContext.Current.Session[“YourSessionVariable”].ToString();  

Read More
ASP.Net WebForms / C# / Devexpress

ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn

- 20.11.19 | 27.11.19 - ErcanOPAK comment on ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn

You can use code below:

Read More
ASP.Net MVC / C# / Razor

@helpers in Asp.NET MVC Razor

- 19.11.19 | 27.11.19 - ErcanOPAK comment on @helpers in Asp.NET MVC Razor

A @helper in Razor ultimately defines a function you can invoke from anywhere inside the view. The function can output literal text and can contain code blocks and code expressions. Don’t forget that heavy amounts of code in a view can lead to grief. You have @PluralPick(Model.Count, “child”, “children”). @helper PluralPick(int amount, string singular, string […]

Read More
C#

How to set delivery format while using SMTP client in C#?

- 02.10.19 | 22.11.19 - ErcanOPAK comment on How to set delivery format while using SMTP client in C#?

SmtpClient smtpClient = new SmtpClient(); smtpClient.DeliveryFormat = SmtpDeliveryFormat.International; You must note that it is only available with .NET Framework 4.5 or later.

Read More
C#

How to trim whitespaces between characters in C#

- 06.09.19 | 22.11.19 - ErcanOPAK comment on How to trim whitespaces between characters in C#

trim() function does NOT remove “all whitespace characters” of your string. So instead of trim(), you can use String.Replace method: string str = “C Sharp”; str = str.Replace(” “, “”); OUTPUT: CSharp or if you want to remove all whitespace characters (space, tabs, line breaks…) string str = “C Sharp”; str = Regex.Replace(str, @”\s”, “”); […]

Read More
ASP.Net MVC / C# / Razor

Using Code Blocks, Mixing Text & C# Code and Comments in Asp.NET MVC Razor

- 06.08.19 | 22.11.19 - ErcanOPAK comment on 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 […]

Read More
ASP.Net MVC / C#

Using View Model to pass Multiple Models in Single View in MVC

- 22.06.19 | 22.11.19 - ErcanOPAK comment on Using View Model to pass Multiple Models in Single View in MVC

In MVC we cannot pass multiple models from a controller to the single view. There are a few solution for that problem. But in this article we will use View Model. Here is the solution:

Read More
ASP.Net WebForms / C# / Devexpress

How to set Tooltip for a particular Devexpress Gridview Column

- 24.05.19 | 22.11.19 - ErcanOPAK comment on How to set Tooltip for a particular Devexpress Gridview Column

You can use code below:

Read More
C#

Null-Conditional (?) and Null-Coalescing (??) Operators in C#

- 04.05.19 | 22.11.19 - ErcanOPAK comment on Null-Conditional (?) and Null-Coalescing (??) Operators in C#

Null coalescing: The null coalescing operator “??” uses two question marks. With it you can use a custom value for a null reference variable. It simplifies null tests. C# program that uses null coalescing operator using System; class Program { static string _name; /// <summary> /// Property with custom value when null. /// </summary> static […]

Read More
C#

Important Tips To Write Clean Code In C# from Debendra Dash

- 02.02.19 | 22.11.19 - ErcanOPAK comment on 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.

Read More
C#

Function with variable number of arguments in C#

- 15.01.19 | 22.11.19 - ErcanOPAK comment on Function with variable number of arguments in C#

By using the params keyword, you can specify a method parameter that takes a variable number of arguments. You can send a comma-separated list of arguments of the type specified in the parameter declaration or an array of arguments of the specified type. You also can send no arguments. If you send no arguments, the length of the params list is […]

Read More
ASP.Net WebForms / C# / Devexpress

Devexpress ASPxGridview Column Grouping in Code

- 12.06.18 | 30.03.20 - ErcanOPAK comment on Devexpress ASPxGridview Column Grouping in Code

The following code shows how to group by two columns (“Country” and “City”).

Read More
ASP.Net WebForms / C#

How to use the second argument of Response.Redirect: True or False

- 11.06.18 - ErcanOPAK comment on How to use the second argument of Response.Redirect: True or False

Response.Redirect(URL, false): The client is redirected to a new page and the current page on the server will keep processing ahead. Response.Redirect(“default.aspx”, false); Response.Redirect(URL, true): The client is redirected to a new page, but the processing of the current page is aborted. Response.Redirect(“default.aspx”, true);

Read More
ASP.Net WebForms / C# / Devexpress

How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components

- 11.06.18 | 22.11.19 - ErcanOPAK comment on How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components

DevExpress.Web.ASPxClasses.ASPxWebControl.RedirectOnCallback(“the_redirect_page.aspx”);

Read More
ASP.Net WebForms / C#

How to use and get HiddenField Value in Gridview

- 11.06.18 | 14.04.20 - ErcanOPAK comment on How to use and get HiddenField Value in Gridview

You can add HiddenField to the Gridview like that:

Read More
ASP.Net WebForms / C#

Display HTPP Headers in C# & ASP.net

- 10.06.18 - ErcanOPAK comment on Display HTPP Headers in C# & ASP.net

using System; using System.Web.UI; using System.Collections.Specialized; public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { NameValueCollection headers = base.Request.Headers; for (int i = 0; i < headers.Count; i++) { string key = headers.GetKey(i); string value = headers.Get(i); base.Response.Write(key + ” = ” + value + “<br/>”); } } }

Read More
C#

Change format of the Day with Leading zero In DateTime

- 10.06.18 | 22.11.19 - ErcanOPAK comment on Change format of the Day with Leading zero In DateTime

You can use both methods: DateTime.Now.Day.ToString(“00”); DateTime.Now.ToString(“dd”);

Read More
ASP.Net WebForms / C#

Add blank item at top of dropdownlist

- 10.06.18 - ErcanOPAK comment on Add blank item at top of dropdownlist

drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty)); drpList.SelectedIndex = 0;

Read More
ASP.Net WebForms / C#

Hide GridView Column on server-side

- 03.06.18 | 22.11.19 - ErcanOPAK comment on Hide GridView Column on server-side

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[index].Visible = false; }

Read More
C#

Fire Combobox SelectedIndexChanged with button code-behind

- 27.05.18 | 30.08.20 - ErcanOPAK comment on Fire Combobox SelectedIndexChanged with button code-behind

myComboBox_SelectedIndexChanged(myComboBox, new EventArgs()); // or (null, null)

Read More
Page 17 of 17
« Previous 1 … 12 13 14 15 16 17

Posts pagination

« Previous 1 … 15 16 17
July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com