Click here to Skip to main content
15,893,588 members
Everything / Programming Languages / C# 5.0

C# 5.0

C#5.0

Great Reads

by David Rogers Dev
Learn how to load related entities using the Entity Framework with simple examples
by Darko Jurić
SIR Particle Filter brief tutorial with samples in C#
by tetsushmz
This article explains how to dynamically create RDLC.
by Daniel Vaughan
Create best-in-breed cross-platform MVVM apps using Calcium for Xamarin.Forms.

Latest Articles

by Roman Kiss
Design and implementation of small tool, tester for exploring Azure IoT Hub with virtual MQTT device
by Ciumac Sergiu
Explains sound fingerprinting algorithm, with a practical example of detecting duplicate files on the user's local drive.
by Mansur Kurtov
This article shows how to use reflections in C#.
by Mahsa Hassankashi
This article enables you to generate table in any database such as Oracle, SQLServer, MySQL, SQLite, Sybase, etc. just by typing table name and its fields. Then you can use NHibernate facilities to make query for data layer.

All Articles

Sort by Title

C# 5.0 

19 Jul 2015 by wafa_7903
Please help me to solve this code if there is error..I have this error message-Conversion failed when converting the varchar value '@IDPRO ' to data type int. .I work with SQL 2014 and VS 2012CLASSES class DataAccessLayer { SqlConnection SQLcn; //This...
19 Jul 2015 by Wendelius
Based on the code the value in @IDPRO variable goes to column ID_PRODUCT in the table. You have defined that parameter as a varcharparam[0] = new SqlParameter("@IDPRO", SqlDbType.VarChar, 50); param[0].Value = ID_PRODUCT;but most likely the column definition in the database is int.
4 Mar 2015 by Member 11473159
Using regedit I was able to add "copy path" option to right click context menu.when I right click on any file and I click "copy path" option then path of that should get copy to txt file....using c#........help me out of this its urgent......thanks in advance....
4 Mar 2015 by Sergey Alexandrovich Kryukov
You can start, for example, with this CodeProject article: .NET Shell Extensions - Shell Context Menus[^].—SA
1 Dec 2014 by Member 11111143
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using...
1 Dec 2014 by DamithSL
there may be a situation where you may not have value for strSql.ToString() then you may end up with empty sql statement for SQL command. debug and check why your code not behave as expected.
1 Feb 2015 by sumitk.cadc
Hi,I am using crystal report in my wpf app for showing reports.its all working fine.but after creating exe when i am going to show reports using APP shortcut(which is created when i install exe) its giving me error like below{"Load report failed."}Inner exception is{"Unsupported...
2 Feb 2015 by /\jmot
You will need to modify two properties in the .rpt files:Build Action is set to "Embedded Resource" by default. Change it to "Content".Copy to Output is set to "Do not copy" by default. Change it to "Copy always".Rebuild, Build deployment package and Publish....
2 Feb 2015 by Sanman Marathe
i faced similar kind of situation while working and even after doing the changes from solution1 above , i realized a stupid mistake a very annoying one though.check the path you're calling the crystal report from, and use the "\" till the end of the path if its being passed dynamically.
21 Nov 2014 by Member 11111143
ublic partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { int[] nos = new int[Convert.ToInt32(txtNo.Text)]; for (int i = 0; i
21 Nov 2014 by OriginalGriff
You forgot the ".Text": cmd.Parameters.Add("@SrNo", txtSrNo);Becomes: cmd.Parameters.Add("@SrNo", txtSrNo.Text);
1 Dec 2014 by Karthik Ravi
Hi,I am tring to unit test my project but it showing error as "Object Reference not set to an instance of an object". someone kindly give me a solution for this problem.I referred all necessary namespace in this project. //Unit Test codeusing System;using...
2 Dec 2014 by OriginalGriff
"i think it may be on "Source Con" in TestConnection method. " Source Con = null;Can't throw a null reference exception - it doesn't refer to or create an instance of any class.However, then next line is likely to: appGlobal.AddText();Check your references to...
2 Dec 2014 by Sergey Alexandrovich Kryukov
You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown. You should not ask a specific question each time you face this little problem. It's much more important to learn how to deal with it all by yourself in all cases. Not to...
2 Jul 2018 by kumarravishankar
if(xyz==1) { if(searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId) { Some 50 Line co code } } else (searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId || (SubTab.AppType == (int)_partner.Form.Homeless) && searchFilter.FormId != null) { Some 50 Line co code }...
2 Jul 2018 by Mehdi Gholam
The way to consolidate code is to create a method/function and put the duplicate code in it and call it from the the duplicate places.
2 Jul 2018 by Maciej Los
In addition to Mehdi Gholam[^]'s answer, i'd like to provide a link to MSDN documentation: Methods (C# Programming Guide) | Microsoft Docs[^], which explains how to create method.
19 Dec 2016 by Member 12821924
Hello Im recieving an "}" expected error, im trying to end my main method after the public class starter. Why am i receiving this error?using System;using System.Collections.Generic;using System.Linq;using System.Data;using System.Diagnostics;using...
19 Dec 2016 by Dave Kreskowiak
Um, you tried to define an entire class inside your Main method in the Program class. You can't do that.If you really think that's the "correct placement" of this code, then you know nothing at all about C# and copied this code from somewhere and have absolutely no idea how it works.
16 Nov 2015 by Sergey Alexandrovich Kryukov
Perhaps it happens because you have some JavaScript code by think it is C#. Use JavaScript code with JavaScript and C# code in C# solutions.-SA
8 Aug 2015 by baotdinh
Hi all,i am learning Angularjs . i have a code:controller.js $scope.save = function (position) { $http.post(serviceBase + 'Positions', { model: $scope.position }) .success(function (data) { });$scope.position already returns an...
25 May 2015 by Member 10627743
I am developing an app in WPF that is going to make use of entity framework CRUD operations, but am stuck at a line of code and could not proceed. in one of the classes there is a red underline on "[Foreignkey("DepId")]" with an error message "'entityframework.models.foreignkeyAttribute' does...
25 May 2015 by Duncan Edwards Jones
You should add the System.ComponentModel.DataAnnotations namespace.See this tip...[^]
18 Mar 2021 by Muthu vj
hi in xamarin form i am facing this Error while clicking the button for navigating another page. can you help me on this how to fix the Error public partial class HomePage : ContentPage { public HomePage() { ...
30 Mar 2015 by star_tasneem
want to dynamically populate dropdownlist. have table of District{district_id,distrint_name} and Thana{thana_id,thana_name,district_id(fk)}.The controller code:public class CenterController : Controller { string connection...
13 Jan 2015 by Nishant.Chauhan80
$(document).ready(function () { var results =[1111$11,1222$22,2333$33]; $('#bttn_Click').click(function () { stringArray = new Array(results); stringArray.split(','); // Error display for (var i = 0; i > stringArray.length;...
13 Jan 2015 by Kornfeld Eliyahu Peter
new Array() can not get an array as parameter...It should be a list of values or nothing...In your case results is already an array so you have 3 options...1. Assign the existing array to the newstringArray = results;2. Clone the existing arraystringArray = results.slice(0);3. Do not...
2 Nov 2014 by Viooz HD
.............................
7 Apr 2014 by Bhatt Aniruddh
hi all,i have two list boxes. i want contact synchronization folder and email synchronization folder in list boexs.i tried following code...private void EnumerateFoldersInDefaultStore(){ Outlook.Folder root = Application.Session.DefaultStore.GetRootFolder() as...
13 Apr 2014 by Member 10306290
I want to create a tool like textbox validation so how to create textbox validate tool in asp.net c#
13 Apr 2014 by syed shanu
you can create Custom Control .Check this links how to create custom controls in ASP.net.Your First ASP.NET Custom Control[^]http://johanmeyer.ukuvuma.co.za/2013/12/14/creating-custom-control-text-box-validation/[^]http://www.tutorialspoint.com/asp.net/asp.net_custom_controls.htm[^]
14 Jul 2015 by Nitin_Bharekar
I am having couple of word files which is having ".doc". but when i saving the file it's showing ".docx" in saving dialog box.Any one having any idea?
14 Jul 2015 by Peter Leow
Refer: http://ats.immaculata.edu/faq/faq/index.php?action=artikel&cat=35&id=340&artlang=en[^]
25 Aug 2015 by Member 11936499
I have implemented a .net webservice, with a method witch receives a DataSet as parameter.Now, I want to implement security based on digital certificate authentication. On the server side, I managed to do this, but I can't manage to implement the client, in order to use the same proxy class...
1 Dec 2020 by octavia81
I'm quite new in .net core. Learning in progress and i'd like to know how much do we need to know ajax, jquery, javascript if we want to get certain level proficiency in .net core web application. I have good enough knowledge in bootstrap css and...
1 Dec 2020 by Afzaal Ahmad Zeeshan
.NET Core is a backend technology in a web development stack, while JavaScript, jQuery (and other derivative technologies, such as Ajax) are for the frontend. If you are hands-on with JavaScript, why not go with Node.js? Node.js[^] If you are...
16 Jan 2015 by Ferz Franco
I'm using the .NET System.IO.Ports.SerialPort using the BaseStream as suggested in this post If you must use NET SerialPortBut when I try to close the port or the baseStream, an...
16 Jan 2015 by Philippe Mori
I would think that tou should only close the serial port but not the base stream as it will get close anyway. The error is probably caused by the fact that serial port assumes that the stream is not closed directly.Thus you should consider that the stream is managed by the serial port and...
7 Aug 2016 by Member 11579281
Upgrading to .Net framework 4.5 . Where's the C# services installer project template? Or is there a new method for installing / deploying services? Thanks!What I have tried:Tried searching through nuget web and found no love.
7 Aug 2016 by David_Wimbley
The way to attach an installer to your windows service is the following steps1) In new project setup, select Windows -> Windows Service project template2) Select/double click on Service1.cs3) Right click on the Design window that opened from step 2, and select "Add Installer"4) You...
24 Feb 2015 by shreyanshd@hotmail.comi
I want to use MemoryCache in distributed environment i.e. to spread on multiple machine. By this i want to access a cache from applications running on different machines. Is it possible to so or there is any other way around.regards,Shreyansh
7 Dec 2014 by DHicks19
Hi,I am trying to read data from a server on our network using VFPOLEDB.1 however I am getting an error:"Invalid path or file name"which is caused by a permissions issue.I have tried using the impersonate in web.config file and also set the application pool account in IIS to admin...
7 Oct 2015 by Sagar Uday Kumar
Windows Shell Extension - Adding submenus to Shell Context Menus and dynamically loading them using sharpshell library.
23 Oct 2015 by Yaseer Mumtaz
XML input parameter to RESTful API using HttpClient and bypassing the SSL certificate
13 Jul 2015 by Praveen Kumar Upadhyay
Hi All,I am trying to generate 1000 concurrent web request and then waiting for the response.So basically my requirement is to hit n numbers of request sententiously and wait for response of each.I have written the below code to do so, but I am not able to generate those many...
13 Jul 2015 by Sergey Alexandrovich Kryukov
Actually, I can see only one problem in your code: you did not handle possible exceptions, so I'm not sure how exactly the problem appears. So, here are my suggestions: Handle all exceptions on the top stack frame of all threads. Display comprehensive exception information. Just in...
7 Feb 2015 by TheBigBearNow
Hello,I hve a small simple program I am working on just to get better at a few things and understand a little bit of code better. Its involving c# and SQL.I have 2 database tables and they have a common field which is ORDERID. I have 2 controls in my C# program a combo box and a datagrid...
7 Feb 2015 by Kochathu Thomas Tinu
Try this code at the click event of comboboxtry{SqlCommand cmd1=new SqlCommand("Select * from buys where OrdersID="+ddlOrders.SelectedValue+"",sqlcon);sqlcon.Open();SqlDataReader readBuys = cmd1.ExecuteReader(); while(readBuys.Read()) ...
3 Oct 2011 by DJAppleboy
I have a Business & Presentation Layer. I am trying to access a method in the Business Layer from the Presentation Layer. // Presentation Layer CodeGrade grd = new Grade();grd = Businesslayer.GetGradeID((int)gradeId);Grade is a Class & GetGradeID is the method in the...
3 Oct 2011 by Al Moje
Hi,Do I am right to say that from your Businesslayer you are retrievingthis list of Grade?If I am right the Declaration on Presentation Layer should be: var grd = Businesslayer.GetGradeID((int)gradeId);grd example contents List of GradeHope this could...
3 Oct 2011 by DJAppleboy
Hi Algem.You understood me correctly. However, im using c# with a normal desktop application so i changed the var to an Object and worked perfectly fine. Regards
6 Apr 2015 by QutaibaMustafa
Hi ^_^ I want to make a 3d painter using c#.First of all I want to display 3 panels - XY, XY and YZ Views. The user will paint what he wants in each panel. After that he will click on a button to combine the 3 views and get a 3d model from these panel. He also can render this model...
14 Apr 2015 by Gokulprasad05
Triangle FarPlaneDistance="100" LookDirection="-12,-11,-10" UpDirection="0,1,0" NearPlaneDistance="1" Position="11,10,9" FieldOfView="75" /> ...
21 Dec 2014 by arussell
How to use C# to create WPF 3D graphics.
16 Jul 2015 by Libin C Jacob
Hi, Could you please use this link to see my question.http://stackoverflow.com/questions/31244814/404-error-while-url-routing[^]Thanks in advance
18 Sep 2014 by Anele Ngqandu
HiHaving issues i cant seem to hit my controller, please helpWeb.xml below.
23 Sep 2014 by Suraj Sahoo | Coding Passion
For 500 Internal server error, you ought to debug and check for the Issue on the server side code. Please debug putting the code block in try catch and then check for exception.ThanksPlease reply after debug. :)
12 Jan 2015 by Branden Coker
Good morning all. I have a problem that I've tried everything I can think of and searched the net and cannot find a resolution. I have a check box that simply tells the database whether a field is true or not. The data side of this checkbox works perfectly both posting and retrieving...
12 Jan 2015 by Branden Coker
I think I found the solution. Sorry to bother you guys. It appears it is the padding that is messing up the check box. I took the padding out of the markup and it stays fixed.
22 Nov 2014 by saadmechiche
Hello everyone, when an object is instantiated we put for ex:person p = new person("john","doe",23);but sometimes it is writen directly like thatp = new person("john","doe",23);without the person prefix before p, is that normal behavior ?Thanks for your help :)
22 Nov 2014 by DamithSL
person p; may have declared before the line of p = new person("john","doe",23); or as class level field or property.then only you can assign new object to p, otherwise you will get compile error.update:Quote:can you please tell what means class level field or property ?method...
22 Nov 2014 by Afzaal Ahmad Zeeshan
Yes that is normal, but only in case if that p variable has been created with the data type to store the person in it. Like this,person p;// add valuesp = new person("john","doe",23);
17 Aug 2015 by Richard MacCutchan
Go to the Youtube developer site[^] and study their documentation.
17 Aug 2015 by robinson_niit
Hi all!As the title above, I want to get links of all videos from a youtube playlist, how can I do that ?Please help me!Thanks and best regards!----Robinson----
17 Aug 2015 by Richard MacCutchan
See [C#] How to get all videos from a youtube channel ID?[^].
4 Jan 2017 by Thomas Nielsen - getCore
Depends of cause what the mega is :)But in general, no.Well you can use the CodeUI library to instantiate a browser, navigate, then pick the login 'controls' and put data, then execute the whatnot login button on that page. Caveat it doesn't work equally well on all browsers.Secondly...
5 Oct 2014 by morzel
How to shoot paintball marker with relay, Arduino and .NET Winforms
2 Nov 2015 by CgKumar
Hi friends,Here i have a problem, which is how to list the contents(files) of a search folder in listbox. The issue is i have many folder, each folder have many files with format .txt. I need, if i type the folder name in textbox and click the button, in the listbox shows all the files...
2 Nov 2015 by CgKumar
Hi Friends, i m settle ready the problem. i do some mistake in code. By the way thanks friends for the help. The modified code is:string[] files = Directory.GetFiles(@"\\192.123.1.16\Report\Result\"+ search, "*.txt", SearchOption.AllDirectories);Regards,Thanes
6 Jul 2014 by ArunRajendra
Looks like its initializing the matrix with random numbers.
6 Jul 2014 by George Jonsson
Hmm, this must be some school homework.It's the second time you ask about this.array[i, j] = lstNumbers[k - 1];The statement assigns the contents of the array element with the index k-1 from lstNumbers into the matrix cell indexed by i and j.You really should read some...
6 Jul 2014 by Peter Leow
You already got good advice, so stop re-posting.
15 Jun 2015 by Andy Lanng
Hi,I have some code that gets a list of tasks from a db message queue. and yields results. This is running quite slowly so I want to multi-thread it. How can I best implement a multi-threaded version of this:private IEnumerable GetData(){ while (!_cancel) { ...
15 Jun 2015 by Andy Lanng
Edit: The solution I went for including tweaks.If you follow the comments, my issue is that there is once process that takes all the time in my ProcessMessage method. There is barely anything I can do while I'm waiting for it to do it's stuff so async was not much of an improvement.I...
24 Aug 2015 by itsathere
aut(document).ready(function () { debugger; aut("#").autocomplete({ source: function (request, response) { debugger; aut.ajax({ ...
24 Aug 2015 by OriginalGriff
Answered only to remove from unanswered list - solved by OP.
18 Jun 2014 by LLLLGGGG
Hi everybody,I have made this in a resource dictionary istantiated in app.xaml:and in a page loaded in a frame inside a window (I put this code inside a...
16 Jun 2014 by ashok rathod
I think problem is with 1.You can use DynamicResource instead of StaticResource.2.Double Quotes is missing so u can put double quotes at the end of Statement and can make TargetType="Button" 3.After doing all above you can clean your solution.Rebuild your solution and can then...
16 Jun 2014 by ashok rathod
I think problem is withshould havebecause it might be the case that MainButton style is not available at runtimeYou can also try...
5 Nov 2014 by Jeong, WonYoung(Brad)
Making BitField with C# alternative to BitField made with union and struct of C++
23 Mar 2017 by Member 13075342
Okay, so I have been learning Xaml and C# for a little now. I designed a application using some basic navigation however I've stumbled into a problem. So for instance I created different dashboards for different types of users. Those only have access to certain pages. Here is an example:I...
23 Mar 2017 by Graeme_Grant
There is no way in WPF Navigation to look at the Back Stack of pages. You have a number of different choices. Here are two off the top of my head:1. Clear history when "User B" logs in: public void ClearHistory() { if (!this.Frame.CanGoBack && !this.Frame.CanGoForward) { ...
31 Jul 2015 by Jesse Glover
Breaking down the MVVM pattern
13 Nov 2014 by Daniel Vaughan
Learn how to combine T4 and a custom markup extension to share and consume image files between projects.
24 Dec 2014 by iamvinod34
I was created a web site in that web site for user purpose profile page also created ... it is opening in one tab but i want even if i open in another tab with out close older tab ... i want it is user login in both tabs
24 Dec 2014 by Suvendu Shekhar Giri
Try to be little more descriptive and with little better English. From your question it is not clear about the problem. From what I understood, following may help.ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('YourPage.aspx');",true);In case this...
15 Apr 2015 by sx2008
An easy-to-use class to prevent multiple instances of your application from opening and focusing/activating the first instance window.
9 Aug 2015 by Keith Barrett
Describes a 'Proof of Concept' project for a Code-First User interface library.
25 Jun 2014 by Appdev(Icode)
Hi(This is my First report using SSRS)I am trying to generate a Report using SSRS in asp.net.My Need is:I want to create a report with the multiple tables(4 tables) which has relation with one another. I have configure each individual table with accepting 1 parameter for eg:...
21 Apr 2014 by Brady Kelly
A dictionary class for storing string descriptions provided by the Description attribute on enum fields.
26 Sep 2015 by Southmountain
Some take-away to improve the quality of desktop software
21 Jun 2014 by User 10230504
i have a error when send email SqlConnection scon_forgott = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString()); scon_forgott.Open(); DataTable...
21 Jun 2014 by Fadi Halboni
change EnableSsl to True, and you need the smtp.Port property..... what is the SMTP port???such as: Gmail port is 587SmtpClient client = new SmtpClient();client.Host = "smtp.gmail.com";client.EnableSsl = true;client.Credentials = new...
21 Jun 2014 by Raul Iloc
The error seems to be related to your SMTP settings.Your SMTP server is not accessible - wrong IP address, username or password. Also the port for SMTP client should be 25 (the default value) but you should check on your SMTP server about it. You could also try to increase the value of...
15 Mar 2018 by Member 10225052
Hi,I have a asp.net mvc5 application.But sometimes I get this error(see below). But the strange thing is that, after I clear cache in the browser the error dissapear.Quote:A network-related or instance-specific error occurred while establishing a connection to SQL Server. The...
15 Mar 2018 by ONEGO SOLUTIONS
TITLE: Connect to Server ------------------------------ Cannot connect to admin-PC or server. ------------------------------ ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not...
20 Dec 2015 by shijo joseph
An easy to implement yet powerful logging library which requires absolute zero learning curve
28 Jan 2021 by z_azad
I have installed Async-CTP-v3 for using new feature of C# 5 but when I tried to run a console application using async keyword/await expression this error appeared:"A Project with an output type of Class Library cannot be started directly.In order to debug this project, add an executable...
30 Jul 2012 by Wes Aday
To get this off the unanswered list, this question was answered here[^]