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
-
20
votes2
answers540
views+ 3 overloads - What would that be?
In some functions appears such a quantity of overloads, That means the higher that number, the slower it is? Note: I used tag C++ and C# why I saw these overloads in these languages. Microsoft…
-
20
votes3
answers8582
viewsWhat are Parallel.For and Parallel.Foreach loops?
I saw the use of Parallel.For and Parallel.ForEach in some places, I know they are loops, but I didn’t understand how and when to use them and I have my doubts. What are loop Parallel.For and…
-
20
votes1
answer422
viewsIs replacing strings with Regex slower than Replace()?
Let’s say I want to do something like this question: How to convert Camelcase to snake_case in C#? You had some answers, but I want to highlight these two. Answer 1 string stringSnake =…
-
20
votes4
answers9040
viewsHow to return 2 or more values at once in a method?
It is common to see examples of methods returning one value at a time. I’ve seen cases where you need to create a class only to package the data and be able to return more values. Use the generic…
-
19
votes7
answers25439
viewsHow to convert a JSON response to a C#object?
I’m making a request and getting a JSON like this: { "id": "1000000000000000", "name": "BrunoLM", "first_name": "Bruno", "last_name": "X", "link": "http://stackoverflow.com/users/340760/brunolm",…
-
19
votes3
answers12047
viewsWhy doesn’t C# allow multiple inheritances?
In C# we can implement several interfaces. However, because we cannot inherit from more than one base class?
-
19
votes2
answers3085
viewsHow to do a spell check in C#?
I need to do an analysis of the words contained in a database. The analysis consists of promoting a spell check only, showing a report on the screen (gridview) with incorrect words. I never…
-
19
votes1
answer6255
viewsAsp.Net Identity, how to use only Roles or Claims?
Returning to the same subject: ASP.NET Identity with Entityframework. Regardless of the size or planning of my project, if I need to use only the part of Roles or only the part of Claims, Is that…
-
19
votes1
answer739
viewsWhat is the difference between "Generics" (Java/C#) and "template" (C++)
In the question What are the differences between Generic Types in C# and Java? the difference between the Generics between Java and C#. We know that C++ does not have Generics, but uses templates…
-
19
votes2
answers5046
viewsWhat is the difference between Isnullorempty and Isnullorwhitespace?
Li here that there is no practical difference between String.Empty and "", and then the doubt came to me. What’s the difference between using String.IsNullOrEmpty(String) and…
-
19
votes4
answers1350
viewsHow to pass string by reference?
I passed a string as a parameter. As far as I know it is passed by reference, so if I change anything in it within the method, when it leaves it the value will continue to change. I took the test…
-
19
votes3
answers1592
viewsWhat is System.Linq for?
I asked that question here at SOPT What is the equivalent of PHP’s C array_map#? And I was curious to know what this is about System.Linq. Because when I tried to use the answer code above without…
-
18
votes1
answer2218
viewsWhat I need to sell a C#system
If I want to sell a standalone system in C#, do I need a microsoft license? Any special registration? Any specific contract? I have some limitation?
-
18
votes1
answer1702
viewsWhat’s the right way to call the C#versions?
There seems to be some confusion with the nomenclature of the versions of C# and the technologies that are related to it. Is there a C# 2005? Or a C# 3.5? How do C# versions relate to . Net, Visual…
-
18
votes1
answer2737
viewsWhat’s the difference between "throw" and "throw ex"?
I saw that the C# allows to do... try { //algum código } catch { throw; } also... try { //algum código } catch (Exception ex) { throw ex; } and... try { //algum código } catch (Exception) { throw; }…
-
18
votes2
answers10850
viewsWhat is the main difference between int. Parse() and Convert.Toint32()?
In C#, there are two ways (among others) to convert other types to int: Convert.ToInt32(valor) and Int32.Parse(valor). What is the main difference between these two forms of conversion?…
-
18
votes2
answers484
viewsIs there an opposite for `contains`?
I have a list: List<int> lista1 = new List<int>(); lista1.Add(1); lista1.Add(2); lista1.Add(3); List<int> lista2 = new List<int>(); lista2.Add(1); lista2.Add(2); To get the…
c# .net entity-framework linq lambda-expressionsasked 9 years, 3 months ago Jedaias Rodrigues 6,718 -
18
votes3
answers1166
viewsWrite Timespan in full
I want to write a static class (can be Extension) to represent the value of a structure TimeSpan in full, in Portuguese. The idea is to always compare the current date (Datetime.Now) with the date…
-
18
votes3
answers703
viewsCan I remove all the using I’m not using?
I took a project here ASP.NET C# and realize that I can remove several "using". I can get out of these using or not? Did the using which is not used in class can be used by someone who is using the…
-
18
votes1
answer314
viewsIs it correct to use a block using inside another using block?
It is correct to use a block using inside another block using as in the example below? or just put the first using? public DataTable Listar(string stringMySql, CommandType commandType,…
-
18
votes1
answer520
viewsWhat am I supposed to understand when they say ". NET"?
I’m starting to learn C#. I already understand what the Runtime and what is CLI, but turns and moves quote . NET as if it was something I should already know, but I do not understand. Just say . NET…
-
18
votes3
answers8119
viewsWhat are the best practices in field validation?
I created an example to illustrate my doubt regarding field validation, the example is composed of two classes Pessoa and ModelPessoa. The class Pessoa has the following attributes: Nome, Idade,…
-
18
votes1
answer489
viewsWhy does the compiler require local variables to be initialized and fields not?
The question Why a variable with default value is usually declared? addresses the question of whether or not to initialize a variable before using it. However this option becomes mandatory when it…
-
18
votes3
answers713
viewsforeach is a loop or iterator? Or can it be both?
In a video tutorial the instructor stated not to fall for the nonsense of thinking that the foreach is a loop, and it was vehement that he was an iterator. There are cases where we can go through…
-
18
votes1
answer201
viewsWhat does _ in C#mean?
I was servicing a system until I came across the following code: object auth; var authContext = HttpContext.Items.TryGetValue("SystemQueryContext", out auth); var result = await…
-
17
votes5
answers2401
viewsHow do I merge two results of a query?
I am developing an application in C# and I would like to know how to put together two results of two darlings SQL in one. I have the following code: public List<MalaDireta> ObterMalaDireta() {…
-
17
votes2
answers4913
viewsHow to check if a file is in use without launching C#exception
I have an application that processes a file queue. I need to open the files for reading and writing. Sometimes the files are in use when I go to process them. How can I check if the file is in use?…
-
17
votes1
answer2946
viewsHow are applications made in C# Windows Forms updated, with version control?
What would be the step by step of such update so that the software after going through some change or update this is reflected to the systems that have the same software?
-
17
votes2
answers9076
viewsMVC Asp.net paging
Currently I work with the data like this: Context returns to me all Bank Customers public IEnumerable<Clientes> ListarTodos() { return contexto.Clientes.ToList(); } In the controller I call…
-
17
votes5
answers2046
viewsCompressing PDF files
Is there such a site PDF compressor which compresses the files of 300k in 90k, I was googling and I couldn’t find anything related to do on c#. Does anyone know of an algorithm that does the same…
-
17
votes2
answers9060
viewsBest practice for logging the system
What is the best practice for registering a log system? public void inserirLog(string Acao) { StringBuilder csql = new StringBuilder(); csql.Append("insert into Log (Acao,data) values(");…
-
17
votes1
answer11086
viewsHow to check the execution time of a method?
Example: I have the Metodo1 and the Metodo2 both have different processing and actions. I want to check how long each takes to run. How do I do that?
-
17
votes1
answer628
viewsWhat is C#metadata?
What is C#/. NET metadata? What are they for, and how can I use them? I was watching a template of Visual Studio, and browsing the files, I came across them.
-
17
votes1
answer154
viewsGuidelines for Visual Assets
I’m developing an app for Windows 10 and on the Microsoft website does not state what is the standard to be adopted for IMage Assets: Square 44x44 Logo, Store Logo and Badge Logo. The image below is…
-
17
votes2
answers319
viewsWhy are the other types of variables not replaced by Dynamic in C#?
I was studying C# and I came across a type of variable dynamic, which, as I understand it, accepts any value I enter. Unlike other variables, for example: If I declare how int, I have to type one…
-
17
votes4
answers936
viewsWhy is the use of Dynamic something to be avoided?
My company works with development, it is a company practice that all codes made are reviewed by another person before they are approved in pull request. Usually my codes have only a few details to…
-
16
votes2
answers1245
viewsWhy is Addrange so much faster than Add?
I’m working on a data integration between two databases, and I’m using Entity Framework for that reason. I then generated the following code, which iterates each record in the Base Situations table…
-
16
votes5
answers14262
viewsHow to sort list with complex object by one of its properties?
I have a list of objects and I want to sort the list by one of the properties (Desc type string), how do I do this? public class Foo { public string Desc { get; set; } // Várias outras propriedades…
-
16
votes1
answer1856
viewsASP.NET MVC - Attribute you write in a View
I need to write a Attribute write a mask validation in the View. Given for example a zip code field, I would like it to mark a Property in the Model with a [CEP], be written in View the following:…
-
16
votes1
answer8416
viewsHow the Lazy Load Entity Framework works
It’s the following guys, from what I saw on Entity to use the Lazy Load you leave the property without keyword virtual, and Ager with the virtual. However, I saw in some blog posts that people use…
-
16
votes3
answers6549
viewsWhat are providers? What is the difference between OLE DB and ODBC?
I need to read files dbf. I found a tutorial to read the same where the author uses these two providers. I only saw differences in the connection string. What are these providers? What is the…
-
16
votes2
answers958
viewsWhat is the difference between: Urlencode, Escapeuristring and Escapedatastring
And which of the three is equivalent to encodeURIComponent javascript? String: 'apostrophe' "double quotes" Stackoverflow! string teste = "'apóstrofo' \"aspas duplas\" StackOverflow!";…
-
16
votes3
answers4284
viewsWhat is the probability of generating a Repeated Guid?
What is the probability of generating a Repeated Guid with Guid.NewGuid()? I am uploading numerous images from my system. The same will be a Multitenancy, and will share the same Deploy, from the…
-
16
votes3
answers7424
viewsWhat are the main differences between VB.NET and C#?
In addition to syntax, what are the main differences between these two languages? Is there any difference in performance between them? Or is there any case where it is extremely advisable to use one…
-
16
votes2
answers10265
viewsUse of DTO and Viewmodel in ASP.Net MVC project
I have an ASP NET MVC 4 project with the following projects: Domain Repository Contracts (interfaces) DTO’s And the web project The web project "sees" only the repository project and it is…
-
16
votes1
answer1184
viewsBest Practices for Insertion, Modification and Deletion with Entityframework
For deletion of records you may not have, but for Insertion and Change I believe there should already be something discussed. Probably the best practice on Insertion and Amendment is Viewmodel s,…
-
16
votes1
answer10829
viewsHow to make the app wait for a while?
It is common to have situations that we need to delay the execution of the code for a period, whether to show or delete a message or something visual shortly after, or to try something again, to…
-
16
votes2
answers1211
viewsWhat is the difference between using (int)variable or Convert.Toint32(variable)?
What is the difference between them? At what times is it more appropriate to use one or the other? Examples: string palavra = "10"; var numero = Convert.ToInt32(palavra); // ou (int)palavra ? string…
-
16
votes2
answers4940
viewsWhat’s the difference between Sessions and Cookies
What’s the difference between Sessions and Cookies? Under what circumstances should I use?
c#asked 8 years, 9 months ago Al Unser Albuquerque 965 -
16
votes4
answers1876
viewsWhat is the sense of an attribute being private and Static at the same time in a class?
I’m studying about the design pattern singleton, and in a code snippet on java, I came across a situation where I was in doubt. Below is the excerpt of the code: public class Conexao { private…