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
-
128
votes7
answers5450
viewsHow to write easy-to-maintain, readable code?
How to know if the code is easy to read and maintain? I usually abstract a large part of my codes, I have a habit of using a lot lambda functions in C#. As this function for CPF validation. public…
-
82
votes7
answers21276
viewsBest kind of data to work with money?
I am developing a project for commercial automation, using PAF-ECF and everything else. Would Aual be the best type of data to work with SQL Server and C# for money issues? Mainly in relation to…
-
79
votes2
answers11641
viewsWhat is Reflection. Why is it useful?
It is recommended to use in projects? How to use? In what situations Reflection can be used?
-
76
votes3
answers5608
viewsWhat does "immutable" really mean?
In that question I did about value types and reference types in C#, it was quoted in the accepted answer that instances of structs must be immutable objects. Reading on wikipedia confirmed that an…
-
74
votes5
answers2194
viewsExceptions consume a lot of processing. Truth or legend?
I’ve seen shows like this : if(!clienteExiste(1)) { return "Cliente não existe."; } and others like that if(!clienteExiste(1)) { throw new Exception("Cliente não existe."); } The second code will…
-
71
votes8
answers49747
viewsHow do I remove accents in a string?
I have a string áéíóú That I want to convert to aeiou How do I remove accents? Need to save to database as a URL.
-
71
votes4
answers25411
viewsWhat is addiction injection?
I have heard a lot about addiction injection. The question is: How, when and what to use?
-
68
votes1
answer19312
views -
65
votes3
answers5311
viewsWhen to use var in C#?
In C#, local variables in the scope of a method can be declared with implicit type using var, and type is solved at compile time: var i = 10; // implicitly typed int i = 10; // explicitly typed…
-
63
votes3
answers24262
viewsWhat is the difference between Ienumerable, Iqueryable and List?
What’s the difference between Ienumerable, Iqueryable and List no . NET? When it’s best to use one or the other? Why does Resharper suggest that I modify the return of that function, for example,…
-
62
votes4
answers2243
viewsHow do I implement wind in a trajectory equation?
Has a game of tank 2D, using the Unityengine in C#, in which it is played on the side of the screen, seeing only the sides of the tanks, in which has the green and red tank. The green need to shoot…
-
59
votes6
answers10591
views -
58
votes7
answers20675
viewsWhat are lambda Expressions? And what’s the point of using them?
When I started using LINQ I saw I could use the famous lambda Expressions. Until I know that x => x * x is a lambda Expression, but I could not explain to a colleague what they really are, and…
-
57
votes5
answers7848
viewsWhat is the difference of string vs string?
I wonder what the real difference is between String (capital letters) and string (s tiny). Apparently the two have the same goals, but which is "best" to use?
-
55
votes4
answers9003
viewsBest way to deal with Exceptions
During my work I learned a way to deal with Exceptions, but I don’t know if it’s very good. Here’s an example of the code: class Program { private static void Main(string[] args) { try { Foo(); }…
-
51
votes8
answers2113
viewsIs using customer validation enough?
Using Javascript validations is sufficient for efficient validation? Example: Date validation. It is necessary to check also in the code? What are the disadvantages of only performing validations…
-
51
votes2
answers4996
viewsMemory allocation in C# - Value types and reference types
In C# there is a difference between the form that memory is allocated by the CLR for reference types (classes) and value types (structures). The difference, from what I’ve always heard, would be…
-
51
votes2
answers1072
viewsIs it possible to process data receipt in Camel Casing using Odata?
In the method Register class WebApiConfig i have configured a CamelCasePropertyNamesContractResolver public static void Register(HttpConfiguration config) { //Resto do código removido para brevidade…
-
50
votes1
answer5366
viewsWhat is the meaning of the operator "?"
I was looking at some codes and I came across the operator ??: static int? GetNullableInt() { return null; } int y = x ?? -1; What is the difference between the first code and the second?…
-
49
votes6
answers32712
viewsAbstract Class X Interface
What is the difference between an abstract class and an interface? I don’t understand when I should use one or the other.
-
49
votes4
answers5144
viewsWhat does the "@" sign on C" mean?
I have the following string @"\\servidor01\arquivos". What is the function of @ in front of the string?
-
49
votes1
answer13752
viewsDifference between Icollection, Ilist and List?
What’s the difference between ICollection, IList and List? When I should use each one specifically?
-
49
votes1
answer2641
viewsWhat does the symbol "$" mean before a string?
Viewing a code here in Sopt, I noticed the use of the symbol "$" and I was left with doubt about its use. What is the symbol "$" before a string? What good is he? Why use it? Example using static…
-
48
votes3
answers8111
viewsNomenclature standard in code for C#
I recognize that it is common for each language to use a pattern to compose its identifiers (variables, constants, objects, controls etc). In the case of C#, what would be the best practices…
-
48
votes3
answers24523
views -
48
votes3
answers11626
viewsWhat’s the use of the reserved word "Yield"?
What is the use of the keyword (reserved) yield? When and where it is used?
-
46
votes2
answers13820
viewsDifferences between If and ternary operator ?:
There is a difference in performance between using an if and a ternary operator in C#? Utilise Resharper (Productivity tool for VS), he insists that the ternary operator is better but doesn’t…
-
43
votes5
answers2270
viewsUsing unused affect performance?
While I was developing, I saw that in most of my classes contained a certain amount of using that were not being used and came to me the doubt of the title. Using unused affects the performance of…
-
42
votes4
answers6910
viewsHow does namespaces work in C#?
I’m studying C# and I came across namespaces. How it works and when it’s applied? If possible some basic example.
-
42
votes3
answers5198
viewsDifference between the use of typeof and is
In C# when I need to check if a variable is of a certain type, I usually use the operator is: if(qualquerVariavel is int) Console.Write("A variável é int"); I know it is also possible to check the…
-
39
votes3
answers25089
viewsWhat is the function of a static method?
Is it just convenience? I mean, it’s unnecessary to instantiate an object to use a function that doesn’t use the data from it. Is there a difference in execution? Memory, processing - resources in…
-
39
votes3
answers23304
viewsWhat is the difference between "passing by value" and "passing by reference"?
I know that in the first the object passed as an argument to a function is copied, and in the second not. I also know that it is extremely unusual in modern languages to pass complex objects by…
-
38
votes2
answers2228
viewsWhat is the difference between a lambda expression, a closure and a delegate?
From what I’ve been reading the three concepts are quite similar, but I was confused as to the clear and exact definition of them. As far as I know, a lambda expression for being understood as a…
-
38
votes2
answers2688
viewsWhy do you usually declare a variable with default value?
In several applications that have been written with strongly typed languages, a variable (usually) is declared with its default value. Example: int x = 0; double y = 0; However, it is possible to…
c# variables characteristic-language typing variable-declarationasked 7 years, 5 months ago UzumakiArtanis 9,534 -
37
votes4
answers1166
viewsWhat are the differences between Generic Types in C# and Java?
I have studied Java for quite some time and am well acquainted with the functioning of generic types in that language: I know that only exist at compile time, that suffer type Erasure at the end of…
-
37
votes2
answers9287
viewsExample of ASP.NET Identity using SQL Server
I still only use the FormsAuthentication but I searched and did not find an example, even if minimal, in portuguese to talk about ASP.NET Identity for MVC. I’m using ASP.NET MVC 5 and…
-
37
votes1
answer28542
viewsWhat are the most relevant differences between C# and Java?
I wanted to know the most relevant differences that I should know exist between these two languages. Why am I asking this here? Because normally in my day-to-day when I ask this question, my…
-
36
votes4
answers10375
viewsDifference between Object, Dynamic and var
I’m running some tests and it seems to me Object and Dynamic perform the same task as opposed to var that once assigned it is impossible to change their type, what is the difference between them?…
-
36
votes3
answers1858
viewsHow to know the right measure of comments?
I went through PHP, C, C++, Javascript and now I’m working with C#. All this time I’ve always heard that it’s important to have well-commented codes, but I never knew the right measure of comments.…
-
35
votes8
answers45010
viewsWhat is the difference between C# and ASP.NET?
What’s the big difference about ASP.Net and C#? I program in C# for desktop, but I can’t understand. C# para desktop (Windows Forms Application) is identical to the C# used in web programming? And…
-
34
votes7
answers14277
viewsWhat can C++ do that C# can’t?
Being a programmer . Net but with an old passion for C++ (which has grown since C++11), I was with this curiosity. I know . Net can be "extended" with C++/CLI, but I would like to know what C# pure…
-
34
votes1
answer1550
viewsWhat is . Native Net?
These days I saw our colleague Maniero commenting on the existence of .NET Native in a response on C# and C++. I saw that Microsoft announced in April 2014 the preview of . NET Native. And searching…
-
33
votes3
answers6154
viewsC# is a compiled or interpreted language?
I’m starting my studies in C#, and I’m wondering if the language is compiled or interpreted? My doubt arises because I heard in a lecture that it is compiled, and others saying that it is…
-
32
votes2
answers1436
viewsWhat it means '~' in front of the constructor of a C#class
Working on a project here at the company, I came across some commands that are now being used more (yield, ??, anonymous type) but until I understood, but one who called my attention by not knowing…
-
31
votes4
answers28968
viewsWhat is the most appropriate way to concatenate strings?
There are different methods for concatenating strings, such as Concatenating with the operator "abc" + str Formatting String.Format("abc{0}", str); Using the Stringbuilder new…
-
31
votes1
answer8090
viewsInternationalization using ASP.Net MVC
How can I implement an internationalization system using Microsoft’s MVC technology? Is there something similar to Android so that my website can support several languages? Is there also some way to…
-
31
votes3
answers1472
viewsHow does an SQL Injection happen?
Why creating parameters for each field that will be updated helps prevent SQL Injection? Example: SqlCommand comm = new SqlCommand("UPDATE Contatos Set Telefone = @Telefone, " + "Cidade = @Cidade, "…
-
31
votes1
answer5828
viewsDifference between Task and Thread
I need to create an executable c# and the question was: Do with thread or do with task? In practice there is some difference between using Task and the "traditional" multi-thread?? It is true that a…
-
30
votes3
answers2867
viewsCapitalizing on C#names
I have in my application given names in capital letters, for example: "JOSÉ DA SILVA". I would like to format as follows: "José da Silva". How to do?
-
30
votes2
answers5203
viewsMethods and properties in C# - advantages and disadvantages
In C# we have properties with getters and setters, which facilitates the insertion and reading of data in an object when some logic should be performed. In other languages, such as Java these tasks…