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
-
29
votes7
answers9251
viewsIn C#, what is the await keyword for?
I was studying this documentation about Asp.net Identity, and in the examples in C# has a keyword that I don’t know, which is the await, example : [HttpPost] [AllowAnonymous]…
-
29
votes3
answers19104
viewsUnderstanding threads in C#
I’m trying to figure out how to use Tasks and asynchronous methods in C#, but every place I see about it in internet mentions a "usual multithreading" form that would be different from the use of…
-
29
votes2
answers12489
views -
29
votes1
answer1530
viewsProperty Vs variables
I’ve always used properties in C# this way: public int Numero { get; set; } Today I asked myself, why do I use this get and set instead of a variable? Is there a difference? I only use it that way…
-
29
votes3
answers8073
viewsHow is the Global Unique Identifier (GUID) generated?
The Global Unique Identifier is generated so that no other will be generated equal, or will almost never have the same number. var unique = Guid.NewGuid().ToString(); Resultado:…
-
28
votes3
answers1436
viewsHow does method management work in C#memory?
In C# there is a clear distinction between value types (structs) and reference types (classes), this distinction being basically the way in which the CLR manages instances of each type. Value type…
-
28
votes2
answers16435
viewsWhat are the out and ref parameters
What is the use of parameter types ref and out of a method in C#? What is the difference between the two? Some example of each one’s use.
-
28
votes2
answers12475
viewsWhat is the Antiforgerytoken?
What is the AntiForgeryToken and what it serves as in an ASP.NET MVC application?
-
27
votes6
answers8712
viewsHow and when to use Finally after a Try?
First I would like to know why in using the finally What are its advantages? It really only serves for when an exit occurs from within the scope of a block try-catch, as when some return or goto…
-
27
votes4
answers1698
viewsWhy use C#extension methods?
What I get with extension methods I don’t earn with inheritance? Simply using it as the same name is complicated, since it creates more confusion than anything else.
-
26
votes2
answers9155
viewsWhat is serialization? When to use? How to implement in C#?
[Serializable] public class Pessoa { public string Nome { get; set; } public string Cpf { get; set; } } There’s only one kind of serialization? What alternatives not to need serialize an object?…
-
26
votes2
answers1892
viewsWhat is the difference, in practice, between "" and String.Empty?
No. NET is noticeable in multiple ways to initialize a string with an empty value, called "quotation marks". Is there a right way to do this? And what would be the practical difference between…
-
26
votes5
answers1461
viewsIs it possible to code the size of the object in memory?
If I need to calculate the occupied space to make any decision has how to figure out the size that each type takes to check how much memory will be occupied if I allocate multiple instances of it?…
-
25
votes4
answers5615
viewsWhat is the difference in the use of the Equals method for the ==operator?
What is the difference in the use of the method Equals for the operator == in situations of comparison between (1) value types and (2) reference types?
-
25
votes2
answers2094
viewsPrinciple of Liskov’s replacement
Liskov’s substitution principle says that if given types T and S being S subtype of T then S should be replaced by T. My understanding is that if I have an instance of S then I can use it in places…
-
25
votes2
answers1593
viewsWhat is the "?" operator?
I am seeing the functions that C# 6.0 brought, and an example of code appeared: C# 5.0 var vendor = new Company(); var location = default(string); if (vendor != null) if (vendor.ContactPerson !=…
-
25
votes1
answer350
viewsOpenssl and ASP.NET Webapi
I am developing an internal application, but in a certain module I will need to travel a certain sensitive data. A priori I thought about using SSL, but due to limitations (non-technical) I won’t be…
javascript c# asp.net-web-api openssl code-reviewasked 8 years, 5 months ago Tobias Mesquita 22,900 -
25
votes1
answer2636
viewsWhat is the difference between const and readonly?
Read-only constants and fields cannot be modified, as can be seen in the documentation: const Constant fields and locations are not variable and cannot be modified. readonly When a field declaration…
-
25
votes4
answers4422
viewsWhat is the difference between & and &&operators?
I was making a simple code with a if two conditions. Everything worked normal and after I went to read, I realized I had written condicao & condicao2 instead of using &&. Even with this…
-
24
votes3
answers4153
viewsCommon encryption algorithm between Java and C#
Problem I am creating a Web Service in C# to be consumed by an Android application (Java), among other information I would like to pass the user credências to login offline on the app. But these…
-
24
votes2
answers4960
viewsWhat is the difference between "lambda" and LINQ? How to differentiate them in a sentence?
I often see terms like LINQ query and expressions lambda. Then the question arose, What I’m doing is a LINQ query, an expression lambda or both? Ex1: var query = Produtos.Where(p =>…
-
24
votes1
answer2966
viewsRoslyn Compiler - What is it, and why was it created?
What is the Roslyn compiler? This is the standard compiler of Visual Studio? Is it open source? Why did they do it? Only for C# or other languages?
c# .net vb.net compilation .net-compiler-platformasked 9 years, 2 months ago Guilherme de Jesus Santos 6,566 -
24
votes3
answers4038
viewsWhat is the difference between using virtual property or not in EF?
I have my models public class Cliente { public int Id {get;set;} public string Nome {get;set;} } and public class Pedido { public int Id {get;set;} public int ClienteId {get;set;} public virtual…
-
24
votes1
answer9723
viewsWhat is Tuple and when to use?
I saw the use in a site and I was left with the doubt of what is Tuple, and when should I use in my project?
-
24
votes4
answers1016
viewsIs the use of "private" in C# classes optional?
What’s the difference between private string abc = ""; and string abc = "";? Is there any difference or is it just the way you write that changes? I did a test with and without the private and saw…
-
23
votes5
answers573
viewsWhy are you wearing shorts?
The guy short corresponds to a 16-bit integer - it is literally syntactic sugar for type Int16. The current processors are all 64 bits, even on the most machines low-end. Some older machines still…
-
23
votes1
answer1280
viewsDifferences between declarative and imperative form of LINQ
What one way can do that the other can’t? There is a difference in performance? There’s one advantage over the other? Example: using System; using System.Collections.Generic; using System.Linq;…
-
23
votes2
answers3644
viewsWhat is the use of using?
My question is about the difference between: //Bloco 1 using (var memoryStream = new MemoryStream()) { //código } //Bloco 2 { var memoryStream = new MemoryStream(); //código } Deep down they seem to…
c#asked 9 years, 5 months ago Felipe Avelar 9,507 -
23
votes3
answers2385
viewsHow important is the use of the word "this"?
What is the real use of using the reserved word this? As far as I can see it makes use or not, but I doubt its functionality.
-
23
votes3
answers478
viewsCan Garbage Collector language be used for games?
I started learning C# and even Java for interest in game development. But I know that many are developed with C++, mainly because I don’t have one Garbage Collector. Of course I know that several…
-
22
votes2
answers5714
viewsHow does it work and use the Stack in C#?
I came to a part of my program where I have to apply a stack (stack) and wanted someone to give me a simple explanation and an example. The program that I’m running right now is a notepad where you…
-
22
votes2
answers2225
viewsCompile string as code
There is how I compile a string within C#? Example: Console.WriteLine(\"Hello World\");. Like a eval javascript? 'Cause I had a project to load a code into a text file or something.…
-
22
votes3
answers10939
viewsHow does the C#lock work?
I was just looking at an article by MSDN, but it was not clear why to use this. class Account { decimal balance; private Object thisLock = new Object(); public void Withdraw(decimal amount) { lock…
-
22
votes3
answers57329
viewsFormat double with mile and decimal
I have the following value: 43239.110000000001 I used this command: txtSomatorio.Text = String.Format( "{0:#.#,##}", somatorio); I got this: 43239,11 How to do to display like this? 43.239,11…
-
22
votes3
answers7874
viewsASP.NET MVC or Webapi?
What is the advantage of using MVC and Webapi (using Visual Studio and C#)? I think that developing in MVC is easier to assemble a form with validations, because just put special attributes for this…
-
22
votes3
answers11209
viewsDifference between Any, Contains and Exists
What’s the difference between Any, Contains and Exists? What is the appropriate context for each of them? (Examples of use) What are the advantages and disadvantages?…
-
22
votes2
answers440
viewsWhat does # mean in the name of some languages?
This may be the simplest possible question, but what does # (Sharp) mean in the C# and F language names#?
-
22
votes1
answer311
viewsClick on Loginbutton facebook on android using Xamarin with Facebooksdk nothing happens
I’m using Xamarin to try to log in with facebook, I already generated the Hash and appid. ( Apparently correct, because previously the app returned me an msg saying that the HASH was invalid ).…
-
21
votes5
answers6769
viewsShould I use GUID or int as the primary key?
I’m about to start a new project in MVC 4 with Entity Framework, searching I found several examples here in Sopt of models that use GUID as ID and some doubts have arisen me: What is the advantage…
-
21
votes3
answers3722
viewsConnecting LED via USB
How can I send a 5V pulse through a USB? Imagine a USB cable that has 4 wires (one generates 5V and the other negative pole). Left over the two central wires. My doubt is as I can read via Delphi…
c#asked 9 years, 9 months ago Julio Santos 221 -
21
votes1
answer3068
viewsHow Do We Really Understand Streams?
Work for a while with C# and . NET and several times I have seen the use of streams out there for reading files, writing HTML response, uploading files and etc. It turns out that I until today did…
-
21
votes3
answers1556
viewsSQL in the code or in the database?
I’m having a big doubt about where I should put mine query SQL, whether in code or bank. Currently I have a Procedure which is mounted according to the parameters I have, ie, filtros. Procedure…
-
21
votes1
answer622
viewsAt what times is it necessary to force garbage collection in C# for better application performance?
Usually I always have doubts about the use of functions for memory release, in which situations should it be used or should it always be used? And mine really will perform better? If possible…
-
21
votes6
answers502
viewsEmpty semicolon doesn’t make a mistake?
I was working on a project and unintentionally bumped into the semicolon that ended up being inserted well after a if. I was intrigued because Visual Studio did not point out as an error, and when…
-
21
votes2
answers8871
viewsHow and when to use Interface?
When should I use an interface, in which situations its use is feasible and which is not feasible and how to use it correctly? I developed an example to illustrate a situation, below: using System;…
-
21
votes2
answers3969
viewsWhat is Garbage Collector and how does it work?
What is Garbage Collector, how it works? When should we care about him?
-
20
votes2
answers25606
viewsWhat kind of data (double, float or decimal) should I use to represent currency in . NET with C#?
Although I am aware of what would be better to use, I ask this question for educational purposes since I see several examples of people using double in C#. But I’ve had problems with double for coin…
-
20
votes1
answer200
viewsHow to make a test fail if it takes too long?
I’m using Mstest which is the default drive testing platform in visual studio and have this test here: [TestMethod] [ExpectedException(typeof(InvalidOperationException))] public void…
-
20
votes7
answers1682
viewsMake the class builder private?
When placing a constructor of a class in C# as private, get the following error: I would like to know the technical explanation for the reason of this error and whether there is any case of use of a…
-
20
votes5
answers1879
viewsWhat is the difference between an explicit cast and the operator as?
Whenever I convert an object to a specific type, I use a cast explicit, for example: private void textBox1_Leave(object sender, EventArgs e) { TextBox textBoxTemp = (TextBox)sender;…