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
-
6
votes4
answers281
viewsIs there a C# feature similar to PHP __call?
I have a lot of experience with PHP and, as I’m starting now with C#, it will be common for me to want to compare one language with another to find out if I can do something similar. In PHP, I can…
-
6
votes2
answers202
viewsWhy do we pass an object to the statement lock?
I’m working with multithreading and fell in a competition case. More than one thread accessed an I/O operation on the same file and so an exception was triggered. To solve the problem, I did so:…
-
6
votes2
answers413
viewsMemory management and release
1) When I create an object in which there is arrays and large variables, defining them as null, will help in the reduction? Within a method Dispose() - before they were of some value. 2) When I call…
-
6
votes1
answer4187
viewsHow to implement Automapper 5.0.2
I set up a project a while back, as follows, A Class called Automapperconfig as follows: public class AutoMapperConfig { public static void RegisterMappings() { Mapper.Initialize(x => {…
-
6
votes1
answer813
viewsSelf Relationship in EF
I’m having the following problem creating two self relationships. When rotating the Update-Database The following error message appears: Unable to determine the main end of an Association between…
c# entity-framework asp.net-mvc-5 entity-framework-6 code-firstasked 8 years, 2 months ago Lucas Ost 319 -
6
votes3
answers1943
viewsRun Python and C# together
How can I in C# import, ie, execute some script in another language (Python)? Example: If you write "R" in a C#program, it executes a file if called ApertouR.py.
-
6
votes2
answers663
viewsWhere to create a Helpers layer?
I need to create a layer Helpers which will contain classes that will be made available for the entire project. These classes will contain functions such as calculations, wipers of string, anyway,…
-
6
votes1
answer6264
viewsUpload file via POST to Webapi
I need to upload a file to a WebAPI, I am using the following code to upload public void Enviar() { WebRequest request = WebRequest.Create(url); request.Method = "POST"; byte[] byteArray =…
-
6
votes2
answers335
viewsHow do the parameters that LINQ methods receive work?
How the parameters within these methods that receive these parameters work: <TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) An example is the method…
-
6
votes3
answers2496
viewsHow do I find the C# version I’m using?
I wanted to know how to find out the version of C# I’m using.
c#asked 6 years, 6 months ago Wallace Maxters 102,340 -
6
votes1
answer220
viewsHow to determine the character’s level by gaining experience?
I created this calculation based on multiples below to determine how much experience the character will need to level up. float NeededExperience(int level, float experienceRatio = 100F) { float…
-
6
votes2
answers152
viewsTreat Exception by code
In Visual Basic 6 there was the command err.number where the error code is demonstrated. I have a C# app that we treat Exception by the description of the message because I did not find the command…
-
6
votes1
answer113
viewsXamarin Forms await is not respected
Good night, someone can tell me why the code below does not respect Wait, in debug the exit order is 1. init save 2. End Save 3. New header ID: 1 instead of: 1. init save 2. New header ID: 1 3. End…
-
6
votes5
answers497
viewsPrint string in reverse
Why can’t I print that string in reverse? I know there is possibility to use another simpler way, but I want to understand the error. static void Main(string[] args) { string frase = "Diego lima de…
-
6
votes3
answers269
viewsHow to search and save a single field?
How can I search a single field of the table change it and save this field without having to search all fields of the table? The reason for this is simple, I have some tables that have more than 30…
-
6
votes4
answers931
viewsHow to verify variables that are not used?
Is there any way to verify which variables are not used within the scope one-class? As in the example below, the variables teste1 and teste4 has no utility within the application, as could locate…
c# visual-studio variables visual-studio-2015 warningsasked 7 years, 11 months ago Marco Souza 12,304 -
6
votes2
answers687
viewsHow is the query generated in Linq mounted when we do UPDATE?
How the query generated in Linq is mounted when we do UPDATE? using ColWebDBContext.DBase.Banco; using System; using System.Web.UI; using System.Linq; namespace DBContext { public partial class…
-
6
votes1
answer111
viewsWhat is type reference?
Was reading regarding the key word ref and I came across a warning that said not to confuse reference passage with type reference. No doubt this warning left me confused and awakened more doubts…
-
6
votes1
answer4278
viewsHow to sign a PDF digitally in C#?
I need to digitally sign one PDF previously created. This PDF is being created through a Web Service who uses the Interop of Office to generate from a Template Office. I already have access to ICP…
-
6
votes1
answer172
viewsCheck string Regex C#
I have a string that can only be composed by X capital and by -. Example : X-XX-XX or else X-X-X-XX-XXX. Where each - a group would be counted and each X one digit. Example 1: the string X-XX-XX has…
-
6
votes1
answer527
views -
6
votes2
answers419
viewsExport graphs from an Excel spreadsheet without Interop
I need to read and write data from Excel spreadsheets, and export some charts using C#. But I cannot use the interoperability library (Microsoft.Office.Interop) for that reason. How can I do? Does…
-
6
votes2
answers1259
viewsHow to get the month or day of the week in Portuguese on C#?
In PHP, through the function strftime, I can return the name of the day of the week or month, in the language installed in the operating system. Example: echo strftime("%d %B", time()); Upshot: 16…
c#asked 5 years, 8 months ago Wallace Maxters 102,340 -
6
votes4
answers1049
viewsString list + . Split()
The command string.Split() separates a string in a array of the kind string[]. How to use the string.Split() to separate strings in a list List < string>?…
-
6
votes2
answers386
viewsRegular expression C# console application
I have a list of words, for example: São Paulo 9000-000 a 9999-9999 Barigui 8000-0000 a 8999-999 I want to take only the numbers, with the same trace and separate, in another list for example, I…
-
6
votes2
answers1072
viewsWhat use is Notmapped?
I’d like to know what the [NotMapped] and when to use it?
-
6
votes3
answers293
viewsHow to know if class instance inherits another class?
I’m using reflection to know if one class inherits another, what I found was this: bool herda = typeof(A).IsAssignableFrom(typeof(B)); But I want to do it in the variable getting your type. Here’s…
-
6
votes1
answer177
viewsWhen to use Memorycache?
I would like a real example, not necessarily a code, on when use the MemoryCache on Web systems. What types of situation ask for its use? A little context: I participated in an interview where they…
-
6
votes3
answers20560
viewsPick first and last name and abbreviate middle names only with the initial
I would like to address the following string: string nome = "Rafael Rodrigues Arruda de Oliveira" With the following criteria:: Keep first and last name; Abbreviate the other names (middle names)…
-
6
votes2
answers163
viewsWhat do these question marks mean?
What do the question marks on that get. What do they mean int? and ?? in this line of code, I have already found examples that used ? and ?? but never so many in a single line and this gets a little…
-
6
votes1
answer6325
viewsProblem with Nuget Packages Visual Studio
Trying to compile the application, I come across the error: Severity Code Description Project File Line Suppression State Error This project References Nuget package(s) that are Missing on this…
-
6
votes3
answers201
viewsRounding up
I have these values, where contrato.Count = 63 and 63/50 = 1.26. I’d like you to round up 2, I’m doing it this way: decimal arrendondamento = contrato.Count / 50; var valorArredondado =…
-
6
votes2
answers68
viewsHow can I indicate the directory where my assemblies should be found?
My company has an installation that hits the gigabyte home. We have a set of applications in our installation that share the same libraries. By default, when . NET executes an application it looks…
-
6
votes2
answers670
viewsAn Exception of type 'System.Outofmemoryexception' occurred in mscorlib.dll but was not handled in user code Asp.net
I’m having a hard time solving this mistake. My goal is to collect data from an Excel file and store it in c#variables, which in turn will be inserted into SQL Server 2012. Reading is done line by…
-
6
votes5
answers146
viewsIs there a disadvantage or is it harmful to use null types?
I always have trouble receiving null values from the database because I forget to use the cancellable types and face the same problem: The type cannot be null This usually happens with attributes…
-
6
votes1
answer138
viewsWhy do auto properties exist in C#?
I have a doubt, because in C# there are auto properties that are usually used like this: public double price {get; private set;} and because she’s a public she can be accessed directly and on top I…
-
6
votes1
answer247
viewsSize of a list list using list.Capacity
Creating a list of lists: List<List<int>> myList = new List<List<int>>(); I add elements in myList with 1 element: myList.Add(1); When I do debug.writeLine(myList.capacity)…
-
6
votes1
answer230
viewsFilter Postgresql Information on Windows Forms screen using Entity Framework
Is there any way to search for the information in postgresql by nickname? But without using alias, only in the field register in the table I already enter the real name for the field? Example:…
-
6
votes3
answers504
viewsMap Many to Many in the Entity Framework
I’m having a problem mapping with the Entity Framework. I have two models, "project" and "company", where in the "company" there can be several "projects". public class Projeto { [Key] public int Id…
-
6
votes2
answers119
viewsC# properties for those who know Java
What a Java programmer needs to know about basic properties (properties) in order to read code written in C#?
-
6
votes3
answers625
viewsHow to treat Nullreferenceexception with Lambda
I have a class to search for DisplayName of my entities, where I pass the entity and class returns a list with the real values and name of each attribute of the entity. My problem itself is when I…
-
6
votes3
answers259
viewsWhich means an "!" exclamation before a string inside an if in C#
Hello, I have a question regarding some "snippets" of a program I am using to "study", the question is, what is the meaning of "!" inside an if before a string, I saw some topics on the site…
-
6
votes1
answer57
viewsWhy can a double var store an int type?
Why a var of the kind double can store a var of the kind int? Using C# int x; double y; x = 5; y = 2*x; Console.WriteLine(x); Console.WriteLine(y); Console.ReadLine();…
-
6
votes2
answers368
viewsHow to get the properties of a type when using Generics C#
I have the following class: public class Pessoa { public int id { get; set; } public string Nome { get; set; } public DateTime DataNascimento { get; set; } } I’ve developed a method to get her…
-
6
votes1
answer83
viewsDoubt about Many-to-Many EF Relationship
I am doubtful in a following rule: I have N Products and N Coins. From this relationship I will have the table Productomoeda: ProdutoMoeda Id - ProdutoId - MoedaID - Nome 1 2 1 ProdutoNome +…
-
6
votes2
answers210
viewsWhat do builders mean by this?
This builder has a this, what it really means? public class HelpController : Controller { private const string ErrorViewName = "Error"; public HelpController() :…
-
6
votes3
answers230
viewsBi-directional asynchronous communication in layers
I have system in Asp.Net MVC (.Net 4.5) divided in layers: That said, let’s get to the problem... I’m trying to create a screen to send emails asynchronously (3 emails at the same time, for…
-
6
votes3
answers106
viewsIs there any way to interpret (parser) from a string Connection to an object?
There is a certain library that I am using where I need to pass separately as parameter, separately, the connection values with the database: Username, Password, Host and Database. I took this…
-
6
votes1
answer363
viewsDemora ao Enviar Email com Anexo
I am trying to send an email with attachment, without attachment, the email sends quickly, without any kind of problem, but when I place the attachment, it takes a lot, matter of minutes, and hangs,…
-
6
votes2
answers574
viewsFaster way to save multiple entities with Entityframework
I have a performance problem in one method, in addition to causing the full use of the CPU server that method takes a long time to run. internal async void NotificacaoIosTodos(string titulo, int…