Most voted "c#" questions
This tag should be used when the question refers to some resource, information or problem related to the C#language. C# ("C Sharp") is a multi-paradigm programming language that has strongly typed variables, is imperative, declarative, functional, generic, object-oriented and component-oriented, which are designed to be executed in . NET Framework.
Learn more…13,899 questions
Sort by count of
-
5
votes4
answers239
viewsIgnore class name in XML serialization
I need to serialize a class for XML, for example: public class Pessoa { public string nome { get; set; } public int idade { get; set; } public Endereco endereco { get; set; } } public class Endereco…
-
5
votes1
answer311
viewsIndividual User Account between MVC and Webapi projects
I have a MVC project with Individual User Accounts, I use Roles for access management and everything works well. Recently I had the need to create a file manager on another server, I created a WEB…
-
5
votes1
answer951
viewsGif to load while website loads!
I am developing a website (MVC), where there is a user option to select an Excel file, and all table data is sent to the database and only then appears a warning of success or failure when recording…
-
5
votes1
answer437
viewsHow to work with CHAR-like Enums using C# and Entity Framework
I would like to know how to map my entity using an Enum of the type char by the Entity Framework, using Fluentapi. I have the following Enum: public enum Zona { Norte = 'N', Sul = 'S' } And my…
-
5
votes1
answer1694
viewsThe 'Oraoledb.Oracle' Provider is not Registered on the local machine
I have a problem that is limiting my work, it is the following, I created a Webservice with a connection string to an oracle database : OleDbConnection con = new…
-
5
votes2
answers2000
viewsWhat is the difference between async Task and void?
I use async Task with await when I need my code to wait for such a task to complete until it performs another process. In the case of methods void, without async-await, my code also does not "wait"…
-
5
votes1
answer529
viewsUpload files with web browser c#
I am developing a process automation system, where my client’s supplier website has a part that needs file uploading. All automation is already developed, missing only this part. I’ve searched…
-
5
votes1
answer557
viewsIs it recommended to manipulate rules with "Try-catch"?
We can manipulate errors in various ways, but the one that will use less code and time of the programmer is the try, present in almost all object-oriented languages. But, when should be used try,…
-
5
votes1
answer117
viewsIs it bad practice to use an "optional" variable inside an object?
When I download a photo on my system, the download process goes through a security method that returns me an object called DownloadResponse. public class DownloadResponse{ public bool IsValid{get;…
-
5
votes1
answer124
viewsAsync methods - return string from UDP
I am developing a code whose goal is to send a package with a string in broadcast and then read the answer (if any), however I want to create a method that just returns the string of the answer. I…
-
5
votes2
answers943
viewsC# - Random primes?
I have a college exercise that is to generate a random prime number, if that number is not prime it should keep generating another random until one is, but it always falls into numbers that are not…
c#asked 6 years, 11 months ago Felipe Lourenço 53 -
5
votes1
answer362
viewsWhat is the best validation strategy before data persists?
I’m used to . NET using C# and Entityframework. And there in the Entity we have the dataanotations. When I create the entity in C#, for example person, just put the datanotaations and the Entity…
-
5
votes2
answers238
viewsHow to find reserved word in a sentence?
I am creating a routine to search reserved words in a text (name of people). I have tested with Contains() and IndexOf(). Works well most of the time. However in some words the return does not…
-
5
votes2
answers260
viewsHow to save changeable parameters in the system?
I have an ASP.NET MVC project and I use web.config to save some parameters that will be used by the system, but should not be changed by any user. Now I have to implement some other parameters that…
-
5
votes1
answer147
viewsError doing UPDATE when setting varbinary variable as`null`
Follows code: var file = Request.Files; var list = new List<byte[]>(); for (int i = 0; i < 4; i++) { if (file.Count > i) { list.Add(ConvertTo.Bytes(file[i])); continue; } list.Add(null);…
-
5
votes1
answer612
viewsWhat tools to optimize a C#code?
Code optimizer tools aim at, for example: - Removal of dead code: removes any dead class, attribute, or method code that is not referenced and used in the project. - Rewrite and reduce functions:…
-
5
votes1
answer100
viewsHow to use expanded property in C#
I have a problem, I created a class containing the following property: public class MinhaClasse { public int Idade {get; set;} } But when I do it: public class MinhaClasse { public int Idade { get{…
-
5
votes1
answer1720
viewsEFD-Reinf: Invalid signature - Failed to verify XML document signature (using C#)
Good afternoon, someone managed to hold the signing of the EFD-Reinf event using C#? I am sending the event signed and is returning the following occurrence: { <?xml version=""1.0""…
-
5
votes2
answers139
viewsCan hashes be different for the same bytes?
I’ve found a flaw or I can’t deal with hashes. I have two bytes arrays random, one generated by an algorithm and one original. I am trying to make the algorithm EXACTLY the same as the original.…
-
5
votes2
answers211
viewsDifference in cast using "as" and "type cast"
A question arose about casting in C#, I see in many fonts using the cast in the following ways. What is the difference between one and the other, when using one way or another? public interface…
-
5
votes1
answer292
viewsIn Winforms how do the datepicker cursor walk when typing the date?
The question is about Winforms' Datetimepicker control. When we type the date, instead of choosing the calendar, the cursor does not walk. That is, we typed the two digits of the day, and instead of…
-
5
votes2
answers675
viewsSearch for files by extension
In a Windows Forms application I would like to know how to search all the files that exist and contain the word teste in the file extension. For example, when opening a folder in Windows and typing…
-
5
votes1
answer157
viewsError converting varchar to integer
By performing the following UPDATE through my API (.NET Core): UPDATE Aula SET WHATEVER = WHATEVER WHERE ID_AULA = @examID Code: string query = builder .AppendLine("UPDATE Aula") .AppendLine("SET…
-
5
votes1
answer114
viewsLoad XML file stream in Xrrichtext
In my application, I receive a array of bytes file XML. With it I create a stream, but when I try to load it and insert it into XRRichText, nothing happens. However, the stream on a user’s computer…
-
5
votes2
answers279
viewsWhat is this "k_BackingField"
I have a project to create a C# Smart Device for Windows CE. I received a code result reverse engineering, but there is a part that I am not able to understand or adapt. Below follows the code:…
-
5
votes2
answers1042
viewsHow to create a Datatable that has a dynamic column structure?
Hello, I need to create a Datatable in my MVC project that will not have predefined columns. The amount of columns should be defined from the amount of data existing in a BD field. I have a field in…
-
5
votes1
answer101
viewsPersist data in related tables (1 x N)
I have these 2 related classes, and the requested class has a Collection of "Itenspedidos"... The Request class: public class PedidoDTO { public int pedidoID { get; set; } public int codigo { get;…
-
5
votes2
answers64
viewsIs expression-bodied recommended? Is there a performance difference?
The extent to which it is recommended, or even good practice to use Expression-bodied? I know that the Expression-bodied allow properties, methods, operators and other function members to have…
-
5
votes1
answer645
viewsMask for formatting Textbox
I was practicing coding on a project like Winforms, A question soon arose: How to apply a phone mask on a Textbox. So the first thing that popped into my head was to use the event Keypress of the…
-
5
votes2
answers103
viewsHttpstatuscode does not exist code 207, 208 and 226
What to do when class HttpStatusCode there is no code 207, 208 and 226 ? Someone already asked the question on Github: https://github.com/dotnet/corefx/issues/4382, I don’t think they did an…
-
5
votes1
answer142
viewsDouble map the same entity
I’m trying to map the same entity twice into another public class Conveniado { public int Id { get; set; } public string Nome { get; set; }…
-
5
votes1
answer672
viewsWhat are Mutexes and when is it advisable to use this feature?
I read about Mutexes and the class Mutex. However, I cannot understand clearly what Mutex is and what this class does. Since I would like to know if I can use this feature to prevent my desktop…
-
5
votes1
answer159
viewsHow to use methods contracts and why?
Reading a book on development . NET, I saw a brief description about methods Contracts and tried to know a little more on the internet. It uses an imperative syntax that is costly and has low tool…
-
5
votes1
answer146
viewsLINQ Lambda | Query Syntax VS Method Syntax Performance
Doubt regarding the construction and performance of querys using Query Syntax and Method Syntax / LINQ Query Syntax: var VendorQuery = from v in vendors where v.CompanyName.Contains("Toy") orderby…
-
5
votes2
answers127
viewsHow to use Groupby according to parameter?
I have my Model account as below: public class Conta { public int Id {get;set;} public int ClienteId {get;set;} public Cliente Cliente {get;set;} public int ContaBancariaId {get;set;} public…
-
5
votes2
answers3064
viewsSwap line break " n" for " r n" in Richtextbox
I have a RichTextBox that needs to count the breaks of lines as "\r\n", but she’s counting as "\n". Example: "Hello, (User squeezes Enter)world!" To RichTextBox interpret like this: "Olá," + "\n" +…
-
5
votes1
answer456
viewsUsing C# Threads for the First Time
I’m trying to make use of C# Threads for the first time, I’m a beginner in the subject, so I’m sorry for the question if it’s too basic. I am using the code below to use such procedure: private…
-
5
votes1
answer687
viewsHow to use the Foreign Key annotation in C#?
I am layman and would love to learn about. I will use in the example Model A and B not to get confused: I saw about the Model A take note Foreign Key in prop virtual Model B virModelB referencing a…
-
5
votes1
answer78
viewsA method can access the properties of the object it belongs to when stored through a delegate?
I’m building a dictionary of the following kind: <string, delegate>, that will access a method belonging to an object of the following class: class Example{ public int Power { get; set; }…
-
5
votes1
answer70
viewsHow to stream video with interval request?
I have a video saved in the database with type VARBINARY(MAX). How can I make a request range ? The following code gets the full video from the database and plays in the variable video_byte; This is…
-
5
votes2
answers133
viewsPrintdocument Printpageeventargs c# wpf Pagesize WPF
I have the following code: PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(arquivoImpressao); pd.DefaultPageSettings.PaperSize = new PaperSize("teste", 300, 600);…
-
5
votes2
answers62
viewsIs there a method of merging equal items into a var list in LINQ in C#?
Hello, good morning, good afternoon or good night, all right? I have a method that obtains products from a database using LINQ in C#, but on that list there are products that are repeated, so you…
-
5
votes2
answers1797
viewsIs there any way to decrease the amount of Else and if?
I should create the conditions for enrolling students based on their age, I was wondering if there is any way to decrease the amount of if in that part of the code: int idade =…
-
5
votes4
answers1546
viewsTake specific value from a JSON or XML
Hello, I have an entire JSON inside a string and I need to turn it into an object in order to access some data... I’ll leave the code below to see if you can help me. My JSON is in that string:…
-
5
votes2
answers345
viewsHow does the rounding of the string format work?
Consider the following code snippet: decimal myValue = 3.045M; Console.WriteLine("Result by Math.Round = " + Math.Round(myValue, 2)); Console.WriteLine("Result by string.Format = " +…
-
5
votes1
answer116
viewsHow to find the intersection between a line and a mathematical function?
I have a problem where I need to find the intersection of two mathematical functions. I have the formula of the first function and two coordinates, where ab and cd are my points. To pass these…
-
5
votes1
answer138
viewsUntreated POO code exception (Get and Set) from C#
The code in question is used to calculate the circle area value using keywords get and set. After I occurred CS1729 error a constructor was created to fix it private double valor; public…
-
5
votes3
answers253
viewsCannot implicitly convert "decimal" type to "int" in C#function code
This code averages the arithmetic or weighted average of the 3 student grades based on your choice of average according to the use of the Equals, code error is exactly this conversion of decimal for…
-
5
votes3
answers325
viewsIs it possible to override a base class property?
I have a class Cliente, which is the basis. In it I have the property Celular with Data Annotation "Required". I wonder if it is possible to use a property Cellular in class ClientePersonalizado,…
-
5
votes2
answers156
viewsWhat is the correct way to do an Replace in a string-like variable?
I need to create a folder on the file server and realized that the variable that receives one of the information is coming with invalid characters ( / : * ? " < > |) for creating a folder on…