Skip to content

ErcanOPAK.com

  • ASP.Net WebForms
  • ASP.Net MVC
  • C#
  • SQL
  • MySQL
  • PHP
  • Devexpress
  • Reportviewer
  • About

Tag: C#

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

How to get value from resx file in C#

- 26.03.22 - ErcanOPAK comment on How to get value from resx file in C#

// Gets the value of associated with key “MyKey” from the local resource file (“~/MyPage.aspx.en.resx”) or from the default one (“~/MyPage.aspx.resx”) //The default location for resx files is App_LocalResources object keyValue = HttpContext.GetLocalResourceObject(“~/MyPage.aspx”, “MyKey”);

Continue Reading ..
C#

How to lock the ciritical code part in C#

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

Continue Reading ..
C# / SQL

How to use SQL RAISEERROR() messages in C#

- 21.10.21 - ErcanOPAK comment on How to use SQL RAISEERROR() messages in C#

DECLARE @MyValue int SELECT @MyValue = Column1 WHERE Column2 > 50 IF @MyValue IS NULL BEGIN RAISEERROR(‘This is my custom message from SQL.’, 16, 1) END ELSE SELECT MyValue END Use an error code within 11-16, or just use 16 for a “general” case. RAISERROR(‘This is my custom message from SQL.’,16,1) Why? Here’s summary of […]

Continue Reading ..
C#

IndexOf() and LastIndexOf() in C#

- 26.09.21 - ErcanOPAK comment on IndexOf() and LastIndexOf() in C#

The IndexOf() method returns the index number of the first matched character whereas the LastIndexOf() method returns the index number of the last matched character. using System; public class StringExample { public static void Main(string[] args) { string s1 = “Hello C#”; int first = s1.IndexOf(‘l’); int last = s1.LastIndexOf(‘l’); Console.WriteLine(first); Console.WriteLine(last); } } Output: […]

Continue Reading ..
C#

How to Validate a DateTime in C#?

- 03.01.21 - ErcanOPAK comment on How to Validate a DateTime in C#?

DateTime myDate; if(DateTime.TryParse(txtBirthDate.Text, out myDate)) { //Valid Date } else { //Invalid Date }

Continue Reading ..
C#

Convert comma separated string into a List in C#

- 03.01.21 | 03.01.21 - ErcanOPAK comment on Convert comma separated string into a List in C#

string myList = “9,3,12,43,2”; List<int> intList = myList.Split(‘,’).Select(int.Parse).ToList();

Continue Reading ..
C#

Converting a List to a comma separated string in C#

- 03.01.21 - ErcanOPAK comment on Converting a List to a comma separated string in C#

List<int> list = new List<int>() {1,2,3}; string.Join<int>(“,”, list) Join has generic overloads. It is so much easier to use it in that way to convert your list to the different types.

Continue Reading ..
ASP.Net MVC / C#

Convert List to List in one line in C#

- 08.10.20 - ErcanOPAK comment on Convert List to List in one line in C#

string sNumbers = “1,2,3,4,5”; var numbers = sNumbers.Split(‘,’).Select(Int32.Parse).ToList();

Continue Reading ..
ASP.Net MVC / ASP.Net WebForms / C#

Checking multiple contains on one string

- 30.08.20 - ErcanOPAK comment on Checking multiple contains on one string

new[] {“,”, “/”}.Any(input.Contains) or you can use Regex Regex.IsMatch(input, @”[,/]”);

Continue Reading ..
C#

Default Values for Data Types in C#

- 13.08.20 - ErcanOPAK comment on Default Values for Data Types in C#

Table below shows the default value for the different predefined data types. Type Default sbyte, byte, short, ushort, int, uint, long, ulong 0 char ‘\x0000’ float 0.0f double 0.0d decimal 0.0m bool false object null string null As you can see, for the integral value types, the default value is zero. The default value for […]

Continue Reading ..
ASP.Net MVC / ASP.Net WebForms / C#

Creating Multiline textbox using Html.Helper function in Asp.Net MVC

- 23.07.20 | 23.07.20 - ErcanOPAK comment on Creating Multiline textbox using Html.Helper function in Asp.Net MVC

@Html.TextArea(“Body”, null, new { cols = “55”, rows = “10” }) or

Continue Reading ..
C#

How to split string and get first (or n-th) value only

- 20.07.20 - ErcanOPAK comment on How to split string and get first (or n-th) value only

string myValueToSplit = “Istanbul, Tokyo, Seoul, Bangkok, Bali, Minsk, Belgrade, Kiev”; var theFirstValue = myValueToSplit.Split(‘,’)[0]; //OUTPUT: theFirstValue = “Istanbul” //You can change [0] as you wish. //For example, if you want to get Kiev, make it [7]

Continue Reading ..
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 […]

Continue Reading ..
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 […]

Continue Reading ..
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);

Continue Reading ..
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

Continue Reading ..
C#

How to select distinct rows in a datatable in C#

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

dataTable.DefaultView.ToTable(true, “target_column”); first parameter in ToTable() is a boolean which indicates whether you want distinct rows or not. second parameter in the ToTable() is the column name based on which we have to select distinct rows. Only these columns will be in the returned datatable. If you need to get distinct based on two columns: dataTable.DefaultView.ToTable(boolean, params string[] columnNames)

Continue Reading ..
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.

Continue Reading ..
Page 1 of 2
1 2 Next »

Posts navigation

Older posts
May 2022
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Apr    

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (332)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (221)
  • Find numbers with more than two decimal places in SQL (191)
  • How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components (190)
  • Confirm before process with ASPxButton in Devexpress (189)
  • ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn (189)
  • How to make some specific word(s) Bold or Underline in ReportViewer (189)
  • Devexpress ASPxGridview Column Grouping in Code (177)
  • Add Constraint to SQL Table to ensure email contains @ (174)
  • Tense Changes When Using Reported Speech (167)

Recent Posts

  • How to put text inside MVC Razor code block
  • How to solve 0xc0000135 application errors after Windows 11 Update
  • How to get the integrity value for a jquery version of script reference in a web page
  • How to get session value in Javascript
  • How to get value from resx file in C#
  • How to lock the ciritical code part in C#
  • How to make theater mode the default for Youtube
  • How to turn off YouTube annotations and cards
  • How to hide Youtube chat windows permanently
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server

Recent Posts

  • How to put text inside MVC Razor code block
  • How to solve 0xc0000135 application errors after Windows 11 Update
  • How to get the integrity value for a jquery version of script reference in a web page
  • How to get session value in Javascript
  • How to get value from resx file in C#

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (332)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (221)
  • Find numbers with more than two decimal places in SQL (191)
  • How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components (190)
  • Confirm before process with ASPxButton in Devexpress (189)

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter

powered by XBlog Plus WordPress Theme