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
-
7
votes4
answers298
viewsHow to implement an Objectset wrapper that works with Linqtoentities?
I need to create a wrapper for ObjectSet to create a centralized access control. The goal is to implement CA without making changes to existing queries in the system, which in this case are spread…
-
7
votes2
answers362
viewsError using File.Delete method within Controller
I’m in trouble in my controller the moment I start a file deletion routine. I am using the method File.Delete(), but he simply does not recognize and returns me the following warning: Cannot Choose…
-
7
votes2
answers2496
viewsHow to know when the user opened an application?
How do I check, while my program is running, if a particular software is opened by the user?
-
7
votes3
answers6710
viewsCheckboxlist on ASP.NET MVC
I need to create a checkboxlist on my page using MVC (Razor). I noticed that there is no Html helper like Html.Checkboxlistfor or anything like that. Someone has some example of how I could do that.…
-
7
votes3
answers476
viewsUnmounting a USB Pen-Drive via code
I wonder how I can do to disassemble a removable drive(Pen-Drive) via c code#.
-
7
votes4
answers4043
viewsBest practices in using BD connections via Entity Framework
When defining the context class in the Entity Framework (example): public class Context : DbContext { public DbSet<Usuario> Usuarios { get; set; } public DbSet<Categoria> Categorias {…
-
7
votes4
answers1531
viewsList all Roles in Checkbox and mark the roles that the User has
I am creating an Asp.net MVC 4 User Management System with two Simple Tables. Users and Roles. I can create users by selecting the roles they will own. At the time of Edit I’m trying to List all the…
-
7
votes3
answers1552
viewsHow to download an image from the internet with C#?
For example, I need to download a sequence of images: http://www.simepar.br/site/fragmentos/radar/simepar_24.gif http://www.simepar.br/site/fragmentos/radar/simepar_23.gif…
-
7
votes2
answers1259
viewsDifference in performance and use situation of numerical types
I’d like to know the difference between the guys Long, Double, Float, Decimal and Int, taking into consideration when is the best use in real cases. Ex: "uses float in interest as it is...". And…
-
7
votes2
answers4310
viewsHow to prevent a property from being mapped to an entity in the Entity Framework?
I need to enter a property in the model class, but when I enter the code first, it says the table already exists and changes have been made. My code: public class Data { [Key] public int Id { get;…
c# entity-framework asp.net-mvc-4 property code-firstasked 10 years, 7 months ago Luciano Azevedo 402 -
7
votes3
answers546
viewsRun program inside Try/Catch
Working with Visual Studio, when an error occurs while the program is running the program hangs and you can’t see where the program crashed and only appeared that error screen. To catch where these…
-
7
votes1
answer541
viewsCustom Roleprovider
I am implementing an authentication with RoleProvider Custom. I have a class Usuario and a class Role with Many to Many relationship. I created a folder in the project called Security and inside the…
-
7
votes1
answer3147
viewsHelp with setting up Dbcontext with Entityframework using good practices
I have my application divided into layers with Class Library and my layer with the Entity Framework, where I set up the DbContext, is the Repository. My inherited Dbcontext class: public class…
-
7
votes2
answers5079
viewsHow to count records (SELECT COUNT) in Linq
How to count records that a query would return in Linq (Entity Framework) in C#? The equivalent in SQL is to do a SELECT COUNT(*). Note that I want to receive the count of records straight away,…
-
7
votes2
answers360
viewsTheoretical doubt - Interface, unique responsibility
Presentation: I created a photo.Cs class that should be responsible for: Calculate the angle of view of the lens; Receive lens zoom (in mm) Receive the cut factor (value multiplied by the lens zoom…
-
7
votes1
answer3070
viewsTo sort a list of objects by TWO properties
On this topic: How to sort list with complex object by one of its properties? is explained as ordering by a property, but as ordering by two? Taking into account the following product class:…
-
7
votes1
answer731
viewsIncrementing the Assemblyversion
I am creating an upgrade solution for an application I have and needed the Assembly version When placing an * on Assembly. [assembly: AssemblyVersion("1.0.0.*")] it started incrementing…
-
7
votes3
answers9362
viewsHow to get the value without a mask from a Maskedtextbox?
I’m wearing a MaskedTextBox for formatting documents. It is working perfectly, but how do I get the value typed in the field without the mask being present?
-
7
votes3
answers4237
viewsDate field 01/01/0001
I’m with a project Asp.net-mvc3 who owns a View that has a field to receive a type DateTime. In the database this field is required. The problem is that whenever I access the respective View, this…
-
7
votes1
answer244
viewsHow to support user-added columns without updating the EF model?
I have an app C# with a model Entity Framework 6 "Database First" created from the basic structure of a database SQL Server, which belongs to a third party software. Users of this software can add…
-
7
votes2
answers2674
viewsReceive indefinite amount of parameters in C#
The method Main(string[] args) receives an array of indefinite amount parameters. But I know this doesn’t work in a common method. How to create a method that takes as many parameters as needed?…
-
7
votes3
answers11852
viewsHow to separate a String according to a separator in C#?
I have a string in this format: string valores = "Numero1#Numero2#Numero3#Numero4#"; How do I tell it in an array of integers to get it: int Numero[1] = Numero1; int Numero[2] = Numero2; int…
-
7
votes2
answers483
viewsLike taking multiple groups in a Regex?
public string site = "http://www.tibia.com/community/?subtopic=worlds&world=Aurera"; private Regex nomedochar = new Regex("subtopic=characters&name=(?<player>.*?)\" >"); public…
-
7
votes2
answers6973
viewsMany Relationship for Many Entity Framework 6
Good morning, I have the following classes: Consul_ca_student: public class CONSUL_CA_Aluno { public int Id { get; set; } public string Nome { get; set; } public int Cpf { get; set; } public string…
-
7
votes1
answer1281
viewsGood Practice when modularizing an application with EF and multi-bank
Let’s say I want to model an application on .NET using the EntityFramework as ORM and use one of its advantages, to be "generic" for several RDBMS. So, for example, I want my application to agree to…
-
7
votes2
answers3113
viewsHow to pick a random string from a list of strings?
Code: nomes = new string[5]; nomes[0] = "José"; nomes[1] = "Carlos"; nomes[2] = "João"; nomes[3] = "Miriam"; nomes[4] = "Estela"; I put an array, but it doesn’t have to be with an array, it can be…
-
7
votes4
answers2652
viewsDo an update with lambda
I have a query in lambda that returns me a list of data. I wonder how I do to update this table of BD using lambda? Let’s say, I have a table called T_PDV and in it a flag field, where LIDO = 1 and…
-
7
votes1
answer183
viewsLambda with different contexts
Is there any way to join two or more tables using Lambda and two different contexts?
-
7
votes1
answer326
viewsC#. Net blocking or non-blocking?
Do the System.Net.Sockets library, using asynchronous operations such as Beginreceive(), Beginread() and Beginsend() work in blocking or non-blocking ways? If I have 100 connections, it will be 100…
-
7
votes1
answer4965
viewsTransactionscope does not transact
I’m trying to use the TransactionScope in C#, I am performing the tests with local bank, but every time I try to execute some method it returns me this Exception: Partner transaction manager…
-
7
votes1
answer1359
viewsCreate AD user with C#
Does anyone have a code for creating user in the C# net ad? I’m new to C# development and I tried through the codes I saw here and I couldn’t
-
7
votes1
answer204
viewsWhat does the "OR" operator do in an Enum?
What the logical operator | (or) does so in that Enum? public enum Status { Running = 1, Inactive = 2, Error = Inactive | Running }
-
7
votes4
answers20874
viewsHow to extract only numbers from a string?
I want to extract only the numbers of a CPF that is in a string in this format; 111.222.333-44 You have to return only: 11122233344…
-
7
votes1
answer10316
viewsHow to fix Entityvalidationerrors
Hi, I need a help. After compiling my project I am getting an error: Validation failed for one or more entities. See 'Entityvalidationerrors' Property for more Details. I have already found that…
-
7
votes2
answers1416
viewsWhat is the behavior of static variables in . NET?
What is the behavior of static variables in . NET? These are stored in heap or in the stack?
-
7
votes5
answers9265
viewsSearch judicial process data on the TJSP website
I am developing an ASP.NET application with C# that will need to consult the proceedings of online lawsuits. So far the only way I could find to get this information was to do the direct…
-
7
votes2
answers1074
viewsIs it efficient to check file modifications by Hash?
Setting I need to implement a file change check between 2 points in my application. *¹ Point 1 - Server - I have a folder where are some product images; Point 2 - Mobile Device - I have a catalog…
-
7
votes1
answer625
viewsDoes using Timer class features (System.Timers) cost a Windows service?
I need to do a database check once a day. I’m thinking of using the class Timer (System.Timers). The time contactor feature will burden/lock the other system services? This solution is advisable…
-
7
votes3
answers1618
viewsHow to intercept exceptions when working with the Entity Framework?
I want to handle errors returned by Entity Framework. In this example I am forcing the insertion of a duplicate record (Name already existing in the database and the table column is configured as a…
-
7
votes3
answers233
viewsnullable on the models?
What is nullable for in a model? For example: public int? ProjectId; If I put it this way I’m accepting null values, right? And if I put the required Annotation in the property, being required it…
-
7
votes2
answers2337
viewsHow to make "Replace" replace all occurrences of a word without taking uppercase or lowercase?
The function Replace supersedes all occurrences of a word or expression, but taking into account uppercase and lowercase: string str = "Hello WorLLd";//Substitui só os 'l' e não o 'L' str =…
-
7
votes1
answer404
viewsCode First Mapping with Data Annotations
I am creating a project using mapping through DataAnnotations with Code First (similar to the Hibernate), without the use of FluentAPI. It turns out that in implementing this process, some…
-
7
votes1
answer1275
viewsHow to save formatted text to database
I’m using Tinymce to edit texts on my website. However, I am doubtful to save the formatted text in the database and then display it the way the user typed it. (paragraphs, font color, etc.). Is…
-
7
votes1
answer135
viewsUse of Waitall in C#
I have the following problem: A program generates two types of A and B threads through clicks on their respective buttons. The two types cannot run at the same time. If I have 10 A threads, B can…
-
7
votes2
answers4616
viewsLogin with network user(AD)
I need to log the user into my system, with the user who is logged in to the company network. I’ve never done this and I’m having doubts about how to get users on AD. I’m doing research on the net…
-
7
votes1
answer580
viewsDependency registration responsibility (Ioc, DI, n-layer architecture)
I’m starting a WPF (.NET/C#) project using an n-layer (Domain Driven Design) architecture, and to implement Control Inversion and Dependency Injection (Ioc/DI), I’m trying to use Microsoft’s Unity…
-
7
votes2
answers297
viewsBest way to do an Action that does not return data
I am making an ajax call to change an object. The call does not need to return anything. Only http 200 (OK) or 500 (error) code. I’m using the following code in the action but I don’t know if it’s…
-
7
votes3
answers2508
viewsHow to work with OCR to recognize photographs
I am currently working on my Course Completion Work and the theme involves OCR. I did some research and found the Tesseract, I also found libraries in Nuget for him (I’m using C#). The problem is…
-
7
votes5
answers1506
viewsRead XML file in C#
I’m having a problem reading an XML file in C#. In which this is a file of a pre-sale, and I am with the following situation: in my xml I will have several pre-sales, and each pre-sale may have…
-
7
votes2
answers415
viewsFluent API with ASP.NET Identity
In accordance with this tutorial, I transported Identity in a class library to encapsulate the system’s business rule. However, the entire system is using Fluent API to map the entities and Identity…