Coder Baba
Kanalga Telegramโda oโtish
Everything about programming for beginners. 1 and only official telegram channel of CODERBABA India. Content: .NET Developer, Programming (ASP. NET, VB. NET, C#, SQL Server), & Projects follow me https://linktr.ee/coderbaba *Programming *Coding *Note
Ko'proq ko'rsatish2 319
Obunachilar
-124 soatlar
-167 kunlar
-2830 kunlar
Postlar arxiv
2 319
โ๏ธ ๐ฅ๐ฒ๐ฝ๐น๐ฎ๐ฐ๐ฒ ๐ถ๐ณ ๐๐๐ฎ๐๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐๐ต ๐ก๐๐น๐น ๐๐ผ๐ป๐ฑ๐ถ๐๐ถ๐ผ๐ป๐ฎ๐น ๐ข๐ฝ๐ฒ๐ฟ๐ฎ๐๐ผ๐ฟ
2 319
โ๏ธ ๐จ๐๐ฒ ๐๐๐ฟ๐ถ๐ป๐ด.๐๐พ๐๐ฎ๐น๐ ๐ถ๐ป๐๐๐ฒ๐ฎ๐ฑ ๐ผ๐ณ ๐ง๐ผ๐จ๐ฝ๐ฝ๐ฒ๐ฟ()/๐ง๐ผ๐๐ผ๐๐ฒ๐ฟ() ๐๐ต๐ฒ๐ป ๐ฐ๐ผ๐บ๐ฝ๐ฎ๐ฟ๐ถ๐ป๐ด ๐๐๐ฟ๐ถ๐ป๐ด๐
๐ Using ๐ง๐ผ๐จ๐ฝ๐ฝ๐ฒ๐ฟ() and ๐ง๐ผ๐๐ผ๐๐ฒ๐ฟ() for case conversion in C# can impact performance due to memory allocation, string copying, and potential garbage collection, especially in situations involving large strings or frequent conversions.
๐ ๐ฆ๐๐ฟ๐ถ๐ป๐ด.๐๐พ๐๐ฎ๐น๐ is faster than ToUpper() or ToLower() due to direct character comparison, avoiding memory allocation, and reducing overhead for case-insensitive string comparison.
๐ฅ To perform string comparison , it's better to use the built-in comparison methods like ๐ฆ๐๐ฟ๐ถ๐ป๐ด.๐๐พ๐๐ฎ๐น๐ with appropriate StringComparison options, which handle case-insensitivity and cultural considerations correctly while maintaining better performance and accuracy.
2 319
โ๏ธ ๐๐ฒ๐ฐ๐น๐ฎ๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐ฃ๐ฎ๐๐๐ฒ๐ฟ๐ป
โ
You use declaration and type patterns to check if the run-time type of an expression is compatible with a given type. With a ๐ฑ๐ฒ๐ฐ๐น๐ฎ๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐ฝ๐ฎ๐๐๐ฒ๐ฟ๐ป, you can also declare a new local variable. When a declaration pattern matches an expression, that variable is assigned a converted expression result.
๐ฅ ๐๐ฑ๐๐ฎ๐ป๐๐ฎ๐ด๐ฒ๐ ๐ผ๐ณ ๐๐๐ถ๐ป๐ด ๐ฑ๐ฒ๐ฐ๐น๐ฎ๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐ฝ๐ฎ๐๐๐ฒ๐ฟ๐ป๐:
โพ๏ธ They can make your code more readable and maintainable.
โพ๏ธ They can help you to avoid errors caused by type mismatches.
โพ๏ธ They can be used to write more concise and expressive code.
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
๐ก๐# ๐ง๐ถ๐ฝ
โ๏ธ๐จ๐๐ฒ ๐ป๐ฎ๐บ๐ฒ๐ผ๐ณ() ๐๐ผ ๐ฐ๐ผ๐ป๐๐ฒ๐ฟ๐ ๐ฎ๐ป ๐ฒ๐ป๐๐บ ๐๐ผ ๐ฎ ๐๐๐ฟ๐ถ๐ป๐ด
โ
The ๐ง๐ผ๐ฆ๐๐ฟ๐ถ๐ป๐ด method, inherited from the System.Object class, is used to convert a value into its string representation. It can be overridden in derived classes to provide a meaningful string representation of the object's current state.
โ
The ๐ป๐ฎ๐บ๐ฒ๐ผ๐ณ keyword, introduced in C# 6.0, is used to get the name of a variable, type, or member as a string at compile-time. It's useful to avoid magic strings in your code and to keep your code refactor-friendly.
๐ ๐ป๐ฎ๐บ๐ฒ๐ผ๐ณ() is the preferred way to convert an enum to a string. This is because nameof() is evaluated at compile time and will inject a string literal that will never change, while ToString() is evaluated at runtime. This means that nameof() is more efficient and can help to improve the performance of your code.
๐ก Using nameof() with enums can lead to mismatched enum member names if the enum changes without recompiling referencing projects, as nameof() provides names at compile-time.
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
โ๏ธ๐จ๐๐ฒ ๐ป๐ฎ๐บ๐ฒ๐ผ๐ณ() ๐๐ผ ๐ฐ๐ผ๐ป๐๐ฒ๐ฟ๐ ๐ฎ๐ป ๐ฒ๐ป๐๐บ ๐๐ผ ๐ฎ ๐๐๐ฟ๐ถ๐ป๐ด
2 319
๐ก๐# ๐ง๐ถ๐ฝ
โ๏ธ๐จ๐๐ฒ ๐๐ถ๐ฒ๐น๐ฑ ๐ฟ๐ฒ๐๐๐ฟ๐ป ๐๐ผ ๐บ๐ถ๐ป๐ถ๐บ๐ถ๐๐ฒ ๐บ๐ฒ๐บ๐ผ๐ฟ๐ ๐๐๐ฎ๐ด๐ฒ
โ
The ๐๐ถ๐ฒ๐น๐ฑ keyword is used in an iterator block to provide a value to the enumerator object or to signal the end of iteration. When used with return, it provides a value, and when used with break, it signals the end of iteration.
โ
The ๐๐ถ๐ฒ๐น๐ฑ keyword is often used for custom iteration over a collection. It's a powerful tool for writing more efficient code. It's worth noting that yield can only be used in the body of methods, operators, or accessors, and those have to return either IEnumerable, IEnumerable, IEnumerator, or IEnumerator.
๐ฅ ๐๐ฑ๐๐ฎ๐ป๐๐ฎ๐ด๐ฒ๐ ๐ผ๐ณ ๐๐๐ถ๐ป๐ด ๐๐ถ๐ฒ๐น๐ฑ:
โพ๏ธ๐๐ฒ๐ณ๐ฒ๐ฟ๐ฟ๐ฒ๐ฑ ๐ฒ๐
๐ฒ๐ฐ๐๐๐ถ๐ผ๐ป: The code in an iterator block (where yield return is used) is not executed until the sequence is enumerated. This can lead to performance benefits because it allows elements to be generated on demand rather than all at once.
โพ๏ธ๐ฆ๐ถ๐บ๐ฝ๐น๐ฒ๐ฟ ๐ฐ๐ผ๐ฑ๐ฒ: When creating a collection that needs to be iterated over, yield can simplify your code by abstracting away the need to create and manage your own collection.
โพ๏ธ๐ ๐ฒ๐บ๐ผ๐ฟ๐ ๐๐ณ๐ณ๐ถ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐: When iterating over large collections or sequences, yield can be more memory efficient because it does not require the entire collection to be held in memory at once.
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
โ๏ธ๐จ๐๐ฒ ๐๐ถ๐ฒ๐น๐ฑ ๐ฟ๐ฒ๐๐๐ฟ๐ป ๐๐ผ ๐บ๐ถ๐ป๐ถ๐บ๐ถ๐๐ฒ ๐บ๐ฒ๐บ๐ผ๐ฟ๐ ๐๐๐ฎ๐ด๐ฒ
2 319
โ๏ธ ๐ฃ๐ฎ๐ฟ๐ฎ๐น๐น๐ฒ๐น ๐๐ผ๐ฟ๐๐ฎ๐ฐ๐ต
๐ The regular ๐ณ๐ผ๐ฟ๐ฒ๐ฎ๐ฐ๐ต loop is a sequential construct. It iterates over a collection or an enumerable in a single-threaded manner, processing each element one after the other. It's a good choice when the tasks performed inside the loop are relatively simple and quick to execute, and there's no need to parallelize them.
๐ The ๐ฃ๐ฎ๐ฟ๐ฎ๐น๐น๐ฒ๐น.๐๐ผ๐ฟ๐๐ฎ๐ฐ๐ต construct is part of the System.Threading.Tasks namespace and is designed for parallel execution of tasks across multiple threads. It divides the input collection into smaller partitions and processes them concurrently on separate threads.
โ
The performance of ๐ณ๐ผ๐ฟ๐ฒ๐ฎ๐ฐ๐ต and ๐ฃ๐ฎ๐ฟ๐ฎ๐น๐น๐ฒ๐น.๐๐ผ๐ฟ๐๐ฎ๐ฐ๐ต depends on the specific scenario. In general, Parallel.ForEach can be faster than foreach if the collection is large and the work being done is well-suited for parallel execution. However, there are some cases where foreach may be faster than Parallel.ForEach.
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
๐ก๐# ๐ง๐ถ๐ฝ
โ๏ธ ๐ฃ๐ฎ๐ฟ๐ฎ๐น๐น๐ฒ๐น ๐๐ผ๐ฟ๐๐ฎ๐ฐ๐ต
2 319
โ๏ธ๐ฃ๐ฟ๐ผ๐ฝ๐ฒ๐ฟ๐๐ ๐ฃ๐ฎ๐๐๐ฒ๐ฟ๐ป ๐ ๐ฎ๐๐ฐ๐ต๐ถ๐ป๐ด in C#
โ
It is allows you to test whether an expression's properties or fields match specific values or nested patterns. It's a concise and expressive way to perform conditional logic based on object structures.
๐ฅ ๐๐ฑ๐๐ฎ๐ป๐๐ฎ๐ด๐ฒ๐:
โพ๏ธ ๐๐ผ๐ป๐ฐ๐ถ๐๐ฒ๐ป๐ฒ๐๐: Can be used to create more concise and readable code.
โพ๏ธ ๐๐
๐ฝ๐ฟ๐ฒ๐๐๐ถ๐๐ฒ๐ป๐ฒ๐๐: Can be used to express more complex conditions.
โพ๏ธ ๐ง๐๐ฝ๐ฒ ๐๐ฎ๐ณ๐ฒ๐๐: Ensures type correctness at compile time, reducing potential runtime errors.
๐ค Which one do you prefer?
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
โ๏ธ ๐ก๐๐น๐น ๐ฎ๐ฟ๐ด๐๐บ๐ฒ๐ป๐ ๐ฐ๐ต๐ฒ๐ฐ๐ธ๐ ๐ถ๐ป ๐# ๐ญ๐ฌ ๐ฎ๐ป๐ฑ .๐ก๐๐ง ๐ฒ
โ
The ๐๐ฟ๐ด๐๐บ๐ฒ๐ป๐๐ก๐๐น๐น๐๐
๐ฐ๐ฒ๐ฝ๐๐ถ๐ผ๐ป.๐ง๐ต๐ฟ๐ผ๐๐๐ณ๐ก๐๐น๐น method is a static method in the System namespace that throws an ๐๐ฟ๐ด๐๐บ๐ฒ๐ป๐๐ก๐๐น๐น๐๐
๐ฐ๐ฒ๐ฝ๐๐ถ๐ผ๐ป if the specified object is null. It is a convenient way to check for null parameters in your code. It can help to prevent runtime errors and make the code more concise.
๐ฅ ๐๐ฑ๐๐ฎ๐ป๐๐ฎ๐ด๐ฒ๐ ๐ผ๐ณ ๐๐ฟ๐ด๐๐บ๐ฒ๐ป๐๐ก๐๐น๐น๐๐
๐ฐ๐ฒ๐ฝ๐๐ถ๐ผ๐ป.๐ง๐ต๐ฟ๐ผ๐๐๐ณ๐ก๐๐น๐น:
โพ๏ธ It is easy to use. Just pass the object you want to check for null to the method, and it will throw an exception if the object is null.
โพ๏ธ It is reduce code size and make it easy to read.
๐ค Which one do you prefer?
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
๐ก The ๐๐๐ถ๐๐ฐ๐ต ๐ฒ๐
๐ฝ๐ฟ๐ฒ๐๐๐ถ๐ผ๐ป was introduced in C# 8 as a more concise and expressive alternative to the traditional switch statement. It allows you to assign a value to a variable based on the value of an expression. In a switch expression, you use the => syntax to specify the value to assign if the expression matches a certain case. The _ is a discard symbol and is used as the "default" case.
โ
Both the ๐๐๐ถ๐๐ฐ๐ต ๐๐๐ฎ๐๐ฒ๐บ๐ฒ๐ป๐ and the ๐๐๐ถ๐๐ฐ๐ต ๐ฒ๐
๐ฝ๐ฟ๐ฒ๐๐๐ถ๐ผ๐ป are used for similar purposes, the switch expression offers more concise syntax and greater flexibility for pattern matching and value assignment, making it a more powerful tool for modern C# development.
๐ค Which one do you prefer?
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
โ๏ธ๐ฆ๐๐ถ๐๐ฐ๐ต ๐๐
๐ฝ๐ฟ๐ฒ๐๐๐ถ๐ผ๐ป in C#
๐ฏ The ๐๐๐ถ๐๐ฐ๐ต ๐๐๐ฎ๐๐ฒ๐บ๐ฒ๐ป๐ has been part of C# since its early versions. It allows you to evaluate an expression against a series of case values and execute code blocks based on the matched case. Each case value must be a constant value that is known at compile-time. After a case block is executed, you usually need to include a break statement to exit the switch statement.
2 319
๐ก๐# ๐ง๐ถ๐ฝ
โ๏ธ ๐จ๐๐ฒ ๐ฟ๐ฒ๐ฐ๐ผ๐ฟ๐ฑ๐ ๐ณ๐ผ๐ฟ ๐๐ง๐ข๐
โ
๐ฅ๐ฒ๐ฐ๐ผ๐ฟ๐ฑ๐ are a feature introduced in ๐# ๐ต.๐ฌ that allows you to create simple, immutable data types. They are particularly useful for representing ๐๐ง๐ข๐ (Data Transfer Objects) because they provide a concise syntax for defining classes that are primarily used to transfer data between layers of an application, such as between the business logic layer and the presentation layer.
โ
๐ฅ๐ฒ๐ฐ๐ผ๐ฟ๐ฑ๐ are best suited for simple data structures, and they are not meant to replace classes for all scenarios. For more complex types with behavior, you may still want to use regular classes or other features provided by C#.
๐ฅ ๐ฅ๐ฒ๐ฐ๐ผ๐ฟ๐ฑ๐ are an excellent choice for creating ๐๐ง๐ข๐ due to their simplicity, immutability, and concise syntax, which helps in writing clean and maintainable code.
๐ง๐ต๐ฎ๐ป๐ธ ๐๐ผ๐ ๐ณ๐ผ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐
2 319
AutoGenerate ID in aspdotnet C#
โโโโโโโโโโโโโโโโโโโ
private void AutoGenerateID()
{
SqlConnection con=new SqlConnection("");
string qr="select 'EMP' + cast(max(cast(SUBSTRING(employeeid,4,5)as int))+1 as nvarchar)as nextkey from tblemployee";
SqlCommand cmd=new SqlCommand("qr",con);
if(con.State==ConnectionState.Closed)
{
con.Open();
}
SqlDataReader dr=new cmd.ExecuteReader();
while(dr.read())
{
if(dr[0].ToString()!="" || dr[0].ToString().trim()!=string.empty)
{
string id=dr[0].ToString();
textempid.text=id;
}
else
{
textempid.text="EMP1";
}
}
if(dr.HasRows)
{
dr.Close();
}
}
________________________________________________
Endi mavjud! Telegram Tadqiqoti 2025 โ yilning asosiy insaytlari 
