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
-
10
votes2
answers513
viewsReflection C#, how does it work?
I’m doing some tests with Reflection, I made this code on the basis of trial and error, so I didn’t understand how exactly it works. This is the enum that I’m wearing: public enum TipoDoAmbiente {…
-
10
votes4
answers271
viewsJavascript equivalent of "Date.now()" in C#?
Here speaks how to get milliseconds using Date.now();, that returns something like 1533144170651. Follows his documentation: The method now() returns the milliseconds since January 1 1970 00:00:00…
-
10
votes1
answer152
viewsSealed class, with private constructor, versus Static class
When "studying" this class, I checked that it is sealed and has the private builder: public sealed class Interaction { /// <remarks> /// CA1053: Static holder types should not have public…
-
10
votes2
answers487
viewsHow to sort by two properties in Linq
I have the following syntax and it’s not working return View(trabalhos.Where(a => a.Usuario == User.Identity.Name && a.Data.Month == DateTime.Today.Month && a.Data.Year ==…
-
10
votes1
answer339
viewsWhat allows a method to be intercepted in C#?
Interception of a method is a technique that can be used to execute a code snippet before executing a main action. That is, in a very simplified way this would also be an example of interception:…
-
10
votes3
answers184
viewsDifferences in the method call
Why some methods can be called consecutively, example: string a = ""; a.Replace("a", "b").Replace("b","c");// o replace foi chamado 2x And others cannot be called the same? ClasseA A = new…
c#asked 5 years, 7 months ago Marceloawq 971 -
10
votes1
answer1562
viewsUnit Of Work + Ioc + Idisposable
I’m putting together a project that I use Uow to facilitate the issue of transactions. In some scenarios, I use several repositories, persisting the data in memory to save at once in the BD using a…
c# database entity-framework dependency-injection iocasked 7 years, 10 months ago Wilson Santos 633 -
10
votes1
answer130
viewsFunctionality of ":" in C#
Recently I was developing a C# application with Visual Studio and I came across a somewhat unusual situation: public void Upload(object model) { FOO: var text = "teste"; } In the code, FOO: does not…
-
10
votes2
answers289
viewsWhen to use record or class on C#?
One of the novelties of C# 9 are the record types, I saw that one of the biggest differences between them and the classes are the methods .ToString() and .Equals() who has a different behavior. But…
-
10
votes3
answers685
viewsPrevent the CMD command interpreter from using the operators passed via parameter/argument?
There is a way to prevent operators present in past arguments, via command line, from being used/interpreted by the interpreter CMD in C, C++ or C#? I want to make use of characters present in the…
-
10
votes2
answers197
viewsWhen to use Lazy<> from C#
Where is a good scenario to use the initializer Lazy<> of the C#? I ask this because I understand the concept behind the Lazy loading (delay the instance of an object to only when it is…
-
9
votes2
answers960
viewsHow to save a cascade collection in nhibernate without putting circular reference?
Always when I try to save an object with a data collection mapped as HasMany I have to put a circular reference so that Nhibernate can save this object in cascade. For example I have the following…
-
9
votes2
answers282
viewsIs there a way to save types not listed in Settings.Default?
In a Windows Forms application I can create configuration properties. However there is the type List<T> or Dictionary<TKey, TValue>. By clicking on "Browse" and searching on mscorelib…
-
9
votes2
answers2594
viewsWhat does it mean and how does an Enum work with the [Flags] attribute?
I was seeing how the class works FileInfo and came across an Enum: [Serializable] [ComVisible(true)] [Flags] public enum FileAttributes { ReadOnly = 1, Hidden = 2, System = 4, Directory = 16,…
-
9
votes3
answers2321
viewsIncrement version automatically, and get version number via code
In the software in which I am working there are users, whose doubts should be met by observing the version number of the software. Something like 10.0.1.1000 configured in project properties. I…
-
9
votes2
answers1921
viewsAsync operations on ASP.NET
When it is advantageous to use asynchronous operations in an application ASP.NET (classic, MVC, MVC Web API)? When do I use the ThreadPool to perform some operations may be useful?…
-
9
votes2
answers1950
viewsClose connection to database c#
I am making a login system and get the message of sql Exception when I try to create new account in the database: MySqlCommand usuaExiste = new MySqlCommand( "SELECT * FROM contas WHERE nome =…
-
9
votes2
answers4809
viewsEntity Framework with Oracle Banks
I am creating an application in which will use an Oracle database, but when inserting the .edmx (Entity Data Model) I came across the following situation! I can’t create a connection with Oracle…
-
9
votes4
answers1531
viewsHow to assign a value to an Enum with binary notation?
To work with hexadecimal numbers, just add 0x in front of the number, this way: var numeroHexa = 0xff1120; The same goes for octal numbers, adding the 0: var numeroOct = 037; But how do you declare…
-
9
votes2
answers6651
viewsImage Upload
I am trying to upload images to my application. I have made a prototype upload, but it does not show the image, but its ID or NAME. And I’m uploading it to a folder I created in my project. My…
-
9
votes4
answers243
viewsWithin a decision structure, does the order of terms change the outcome?
Is there any difference between: if (variavelA == variavelB) and if (variavelB == variavelA) In Java and C#, is there a difference between the examples? I stress that the question is not limited to…
-
9
votes1
answer17765
viewsFill Data Grid View with object property
I have a form where I need to fill out a DataGridView with data from a user list. To generate this data, I used 3 classes: User class namespace TesteDataGridView { public class Usuario { public int…
-
9
votes4
answers2855
viewsHow to merge multiple text files into one?
Does anyone know how to select all text files from the same directory and join the information of all of them in just one final text file? Example: In folder X, I have files 1.txt, 2.txt and 3.txt.…
-
9
votes1
answer871
viewsChange class template in Visual Studio
There is a way to configure Visual Studio to create classes with public? When creating a class by template, either by menu dropdown mouse over a class name not yet existing, or by adding a class in…
-
9
votes3
answers4278
viewsCreate a class dynamically in C#
I have a class "Classea" and this has an attribute "Attribute" protected. public class ClasseA { protected string Atributo { get; set; } public int Codigo { get; set; } public ClasseA (int codigo) {…
c#asked 10 years, 2 months ago TortugaGonca 93 -
9
votes2
answers717
viewsReceive variable value without passing parameter
I have the following method: private string toCamelCase(string text) { text = string.Format("{0}{1}",text.Substring(0, 1).ToLower(),text.Substring(1)); return text; } To use it I need to call it…
-
9
votes3
answers1650
viewsHow to make a POST that passes beyond the form, a file?
My question is the following: I can pass to the controller OR the file OR form. I wanted to know if there is any type (like Formcollection, but this apparently only receives the form itself, the…
-
9
votes1
answer395
viewsConcat() VS Union()
What’s the difference between Concat() and Union() ? When to use Concat() and when to use Union() ? Can only be used in list ?…
-
9
votes3
answers563
viewsWhich application layer is aimed at processing the most extensive and complex business rules?
I’ve been reading some questions and answers about the MVC standard and I saw that they say that the treatment of business rules in the layer is correct Controller, such as: Check if a record…
-
9
votes2
answers1138
viewsWhy can’t the implemented methods of an interface be private?
When I implement an interface in my class, why your implemented methods cannot be private/protected/etc? And another question, when I implement an interface method explicitly, why can’t this method…
-
9
votes2
answers3468
viewsBest route calculation algorithm
I’m doing a logging system that addresses the issue of routes/routing. Where I should choose the best route to travel. Initially I am only doing some tests and testing advanced algorithms, what I am…
-
9
votes1
answer515
viewsWhat are the pros and cons of the Task<List<Object>> implementation on List<Object>
What are the advantages between the two implementations below. Both return a list with multiple products (more than 1k): public Task<List<Product>> GetAllProductsAsync() { var query =…
-
9
votes1
answer5672
viewsLeft Join with lambda Groupjoin and with condition
How can I make one left join with some conditions using lambda LINQ expressions? In SQL Server have this query: select usr.Id, usr.FirstName, usr.LastName, ex.Id from User usr left join Exam ex on…
-
9
votes1
answer8805
viewsSeparate string by number of characters
I’m developing a component to read the file sent by Dataprev with the list of monthly obituaries. This file is a TXT and every 210 characters is a different person. The documentation can be seen in…
-
9
votes2
answers238
viewsHow to create operators in C#?
How to create an operator in C#? For example, There are operators like: * multiplicacao / divisao % percentual The question is: How can I create my own operator? For example: 100 ~ 2 = 200.8 Where ~…
-
9
votes1
answer2403
viewsWhat is Cultureinfo.Invariantculture?
I installed Resharper and on that stretch x.Id.ToString() he suggests changing to x.Id.ToString(CultureInfo.InvariantCulture). What is CultureInfo.InvariantCulture and why that way is better?…
-
9
votes1
answer188
viewsHow to use Ivalidatableobject?
How to use the IValidatableObject not to validate a foreign key property during a registration? I want to validate only the foreign key in the edition.
-
9
votes1
answer1033
viewsGet index back to front
Imagine I have the following string: string texto = "Stackoverflow em Português"; If I want to know the index of the first space, just: int index = texto.IndexOf(" "); But in this case I have two…
-
9
votes2
answers1919
viewsWhen should I use GC.Suppressfinalize()?
In . NET, under what circumstances GC.SuppressFinalize()? What are the advantages of using this method? Obs: I found answer in the SO-en: When should I use GC.Suppressfinalize()? As it had nothing…
-
9
votes2
answers3327
viewsHow to make a motion system using touch in Unity?
When sliding your finger up screen executes the command and when sliding your finger down executes the command, an example of command would be a move up and a move down with the touch me return a…
-
9
votes2
answers229
viewsuser tree with dots and profile in C#
I have a list of users in which each has a sponsor (sponsor is also a user). Each user has points and is of one type. I want to know which branch of the tree has the highest number of points and for…
-
9
votes1
answer266
viewsProblem with Fast Colored Textbox (indentation)
I’m modifying an open source project created by Pavel Torgashov, called Fast Colored Textbox, and I’m having problems with the language VB in the editor, because methods and properties are indented…
-
9
votes1
answer298
viewsFind slow point in code . NET
I need to analyze a code that is taking too long to execute, the method code is extensive and makes several calls to other methods, I was thrashing to try to identify the point of slowness, but so…
-
9
votes1
answer296
viewsWhat are Sockets? And how to develop in C#?
I have to develop a socket, but I don’t know what it is or how it works! I wanted to know what it takes to create a C#Socket, I am using Visual Studio as IDE.
-
9
votes2
answers2804
viewsWhat is the "connectionString" connection string?
What is after all to string connecting? In a string of connection what represents the data-source? And the provider name?
-
9
votes1
answer120
viewsDifferences between readonly Func<> and method
Forgetting a little questions like readability, what would be the differences between the following calls? readonly Func = (T1, T2) => { Return default(Tresult); } private readonly Func<int,…
-
9
votes1
answer209
viewsStrange property initialization
While reading a tutorial on Entity Framework, I came across an example of code where there was a line that, for me, is unknown: Student stud = new Student() { StudentName = "New Student" }; I…
-
9
votes3
answers382
viewsDesign Standard for Filters
First, filter in my current context is a list of objects to be used in Combobox type controls so that the user can choose from among the options. My scenario is this: Screen 1 - Has filters of…
-
9
votes3
answers2573
viewsIs it possible to avoid using ifs in these cases?
I have read many materials on the internet about OOP, the overwhelming majority says to avoid if/else at all costs. For an OOP beginner like myself, many doubts arise. For example: if…
-
9
votes1
answer22992
viewsAccess Mysql with C#
I’m creating a Form simple that has 3 TextBoxes and 3 buttons and I want to save the information typed in Textboxes in a table. I’ve already created the querys all within a class acessoBD, but I…