C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

Share tech news, updates, or what's on your mind.

Sign up to Post

(Even tho I've resigned, I still want to help the team out before I leave on Friday)...

Our code is MVC , C# with EF 6. The mid developer on the team is going on and on about adding IoC to the code, gut it out whatever , to add unit testing. He said IoC for unit testing because we don't have any unit testing in the solution.

What is he talking about?  It's not a huge solution and not a complicated project.

I found this
https://stackoverflow.com/questions/1465849/using-ioc-for-unit-testing

and this http://duanenewman.net/blog/post/better-unit-testing-with-ioc-di-and-mocking/

I know this an open question... but should he do this? Would it add complexity to the code that's already suffering from performance issues and is an old code....written 5 or 6 yrs ago.
0
I am pulling data from an API and I believe it is returned as a JSON string, how can I read certain data from the string ?  There are rows of data I want to loop through and put in a datatable, but can not figure out how to extract the data.

I have attached 3 files - the first 2 is the data I want to access, the third is the name of the columns.

Path to Column NamesWhere the data is - Label and Value are two fields inside I want to access.Path To Data
0
How to add a reference to Microsoft.Web.Management.Server reference in my c# project?
0
i use mailchimp to send email. usually just upload the csv list to mailchimp. nowday, my website is growing and some user changes email address. but i do not know how to keep track. so sometime, i uploaded the csv list with different email address. and when i upload to mailchimp, and sent. it ends up sending two emails.

In this case, how should i handle it?
0
i have subscription website that I want to auto debt our customer e.g. $5.00 per month and make the charge on every 1th of the month.
can paypal or other provider can do it? if yes, can you please show me their api how it works in c#? thanks
0
i have mvc / razor /c# app. It is reporting portal with ms sql server.
I use typically mvc template to built the app. and sometime, when I need to response back a big data using ajax call, it is just exceed the limit even i max up the webconfig.

can you show me some codes what i can do better? maybe I can zip down the size when ajax response come back to html in javascript or use json format at all time.
now my app response back to html string only.

Thanks
0
I choose to print numbers 1 to 5 in this code.  When I step through it using F11 I get to the line
return stval;

Open in new window

It goes to the end of the routine, but does not go back to the calling command  
printNatural(1, ctr);

Open in new window

Instead it goes back to  this line of code
return printNatural(stval + 1, ctr);

Open in new window

several time before it goes back to the static main method.
Why does it not go straight back to static main after
return stval;

Open in new window


using System;

namespace ConsoleApp10
{

    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("\n\n Recursion : Print the first n natural number :\n");
            Console.Write("---------------------------------------------------\n");
            Console.Write(" How many numbers to print : ");
            int ctr = Convert.ToInt32(Console.ReadLine());
            // Call recursive method with two parameters.	
            printNatural(1, ctr);
            Console.Write("\n\n");

        }
        static int printNatural(int stval, int ctr)
        {
            if (ctr < 1)
            {
                return stval;
            }
            ctr--;
            Console.Write(" {0} ", stval);
            return printNatural(stval + 1, ctr);
        }
    }
}

Open in new window

0
Hi

I'm extracting links from html using HtmlAgilityPack  but i'm getting a lot of unwanted rubbish

I have a list of wanted hosts how might I filter the links against this list?

using System;
using System.Xml;
using HtmlAgilityPack;
using System.Text.RegularExpressions;

					
public class Program
{
	public static void Main()
	{
		var html =
        @"<body>
    <div class='content'>
      <div id='post_message_30829575'>
        <a href='https://example.com/foo/123adj'><img src='https://example.com/foo/123adj/thumb.jpg'></a>
        <a href='https://example.com/foo/bar'>Link to foo bar</a>
        <a href='https://wanted.com/foo/bar'>Link to foo bar</a>
        <a href='https://rubish.com/foo/bar'>Link to foo bar</a>
      </div>
    </div>  
  </body>";

        var htmlDoc = new HtmlDocument();
        htmlDoc.LoadHtml(html);
		string [] hosts = {"exasmple", "wanted"};

         var HTMLBody = htmlDoc.DocumentNode.SelectSingleNode("//body");
            foreach (var Node in HTMLBody.DescendantsAndSelf())
			{
				var linkNodes = Node.Descendants("a");
				foreach (HtmlNode linkNode in linkNodes)
				{
					HtmlAttribute link = linkNode.Attributes["href"];
					HtmlNode imageNode = linkNode.SelectSingleNode(".//img");
                                       // Don't need images
					if(imageNode == null)
					{
						Console.WriteLine("Link value: {0}", link.Value);
					}
				}
			}
		
		
	
	}
}

Open in new window

0
I have searched on Google about creating view without controller but most of them shown me I can do it using redirect so I try out.

the result is because the app redirect so many time n it ends up it time out or generate error message.

if you have the same situation please show me how to handle this.

the reasons we don't want to use controller is because we will create many landing page from our web designer. and there is no need to generate any model, but we do want to use cshtml to do some server side work.

thanks
0
I need to be able to run the following in visual studio using vb.net. :

# Use the command below to dump the JSON data for your orders. Replace the `2c493d74` with your own API key (which will be much longer)
curl -u 2c493d74:X "https://app.handshake.com/api/latest/orders"

Make sure to replace the 2c493d74 with your own API key.
I downloaded https://curl.haxx.se/download.html and it does run

I have been playing about with code like the following as well.

   Dim credstring As String = "apikey:X"
            Dim authstring As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(credstring))

            Dim webrequest As WebRequest = webrequest.Create("https://app.handshake.com/api/latest/orders")

            With webrequest
                .Headers.Add("Authorization", "BASIC " & authstring)

                Dim webresponse As HttpWebResponse = .GetResponse() '

                Dim stream As System.IO.Stream = webresponse.GetResponseStream()
                Dim reader As New StreamReader(stream, Encoding.UTF8)
                Dim contents As String = reader.ReadToEnd()
                Debug.Print(contents)
            End With

Just looking for the easiest solution. Been searching for CLIB integrations into vb.net.

Best Regards,

Ross
0
i have  @Html.Partial("~/Views/Shared/_ListingsSubEvent.cshtml", "13") on razor
how to capture the value(13) on _ListingsSubEvent.csthml?
0
What "transcribe wav file to text" locally installed (non-cloud) software recommendations do you have since I have about 10 .WAV files I want to save as text in notepad/etc and do not want to spend over $50 for everything ?

Examples
 1. https://www.youtube.com/watch?v=hp_hBuq7sys
 2. http://www.lrc.columbia.edu/free-technology-transcribing-audio-interviews-with-transcriber-and-audacity/

Below are some CLOUD solutions (I want non-cloud if possible for SECURITY reasons)
 1. https://www.ibm.com/watson/services/speech-to-text/
 2. https://cloud.google.com/speech-to-text/
0
(I don't know where to put this so I put in C#/ASP.Net category)..

For those of you who've been helping me and know I've been dealing with an abusive and moody manager for almost a year... I accepted an offer today.  I've been practicing my resignation since my manager blew up on me in January...over some silly SQL indentation... can you believe it?!...but now I'm not happy about it. Why is it so easy for companies to see good people come and go but so hard to dicipline a manager? (I'm the 3rd one leaving this company). Why is it so easy to see good people come and go but so hard to send a manager to training?

The position I accepted is a little outdated in technology. They said it's Web Forms and Crystal Reports but open to upgrades.  Another developer does Angular and web stuff. Someone else does other stuff. Solid company and the owner also spoke with me. Seemed like a really nice person and my future manager said he has no tolerance for bad behavior.

I had another potential offer that with more recent technologies but they were taking their time and they're like a startup. They've already had layoffs and the company has been bought out. I chose the solid company with a good 401K (I'm getting older and not younger :)) , 3 weeks of vacation and a little increase in my salary. I chose a manager over technology (I read an article on LinkedIn about it). They did say they're looking into AI and new stuff. I do side projects so I can keep up with newer technologies.
9
I'm writing a .NET Core application in Visual Studio 2017.
This code generates a list from a comma separated set of string values.  How can I unit test it?  I think my difficulty is that the list is of type card rather than a simple string.

 
//2H,3C should generate a list
//2H3C should generate an exception as there is no comma
//2H,2H should generate an exception as the cards are duplicated
//2H,JR,JR,JR should generate an exception as there are more than two jokers

CardApp.Controllers.CardsController ScoreTest1 = new CardApp.Controllers.CardsController();
            List<CardApp.Models.Card> Deck = new List<CardApp.Models.Card>();
CollectionAssert.AreEqual(new List <CardApp.Models.Card>(){ }, ScoreTest1.SetUpList( "2H,3C"));

Open in new window



        public List<Card> SetUpList(string s)
        {
            


                for (int i = 2; i < s.Length; i += 3)
                {
                    if (s.Substring(i, 1) != ",")
                    {
                        throw new Exception ( "Deck must consist of two digit card followed by comma");
                        
                    }
                }
            List<Card> cards = new List<Card>();
            foreach (string item in s.ToUpper().Split(',').ToList<string>())
            {
                Card temp = new Card(item);
                bool cardExists = cards.Any(x => x.Value == temp.Value && x.Type == temp.Type);
                if (!cardExists)
                {
                 

Open in new window

0
Hi,

I have following codes.
I have myCollection variable that contains all the Web elements.  I am using two paths using XPath and or('|') operator because I need different things from the objects that these two different paths gives.
From the elements from the first path(//div[@role='region' and //@my-label] ), I want to get Text properties.
From the elements from the second path(//button[@role='button' and //@my-label]), I want to get the values of 'my-label' attributes. (the Text properties for this elements are "")
After that, I want to put all these too myList<string>.
Obviously I am getting errors on my Linq query(at Select statement).
What's should I do to accomplish this?


public IReadOnlyCollection<IWebElement> myCollection => _driver.FindElements(By.XPath("//div[@role='region' and //@my-label]  | //button[@role='button' and //@my-label]"));

var myList = new List<string>();
myList = myCollection
                    .Select(a => a.Text or a => a.GetAttribute("my-label").ToString()) 
                    .Reverse() // Newest item first
                    .Where(a=>!String.IsNullOrEmpty(a))
                    .Where(b=>!String.IsNullOrEmpty(b))                              
                    .ToList();

Open in new window

0
I have list of pictures for each product in the file folder. all are jpg

1. how can I add text eg. product name in the center of the picture and link them together like a slide show.

2. after that , I hope to create a file as mp4

is that possible written in c# ?

thanks
0
Can someone help me with the logic of looping through an array.
I would like to identifying like strings in a specific location [i,2] and add the associated values in [i,3] and save the results into a new array or list.

Graphically trying to do this.

Example
Thanks for any assistance.

Regards,
Jed-
0
How can I convert a (Base 64) UTF16 string to a standard string  in vb (or C#)
0
Hello,
I am getting below error :
 
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
   at System.Data.SqlClient.SqlBuffer.get_Int64()
   at System.Data.SqlClient.SqlDataReader.GetInt64(Int32 i)

Open in new window


This comes on line row[7] where it is assigning Date value. This is assigning to DataRow in Datatable , Please help.Thanks I checked there are data available in reader there is nothing like NULL for data. There is data present.


                    while (dr.Read() == true)
                    {
                        
                        if (Uid!= dr.GetInt32(0))
                        {

                            row = table.NewRow();
                            rectificationId = dr.GetInt32(0);
                            row[0] = dr.GetInt32(14);
                            row[1] = IdTest; 
                            row[2] = dr.GetString(1); 
                            row[3] = dr.GetInt32(2); 
                            row[4] = dr.IsDBNull(4) ? 0 : dr.GetInt32(4);                           
                            row[5] = dr.IsDBNull(6) ? string.Empty : dr.GetString(6); 
                            row[6] = dr.GetString(11); 
                         [b]   row[7] = new DateTime(dr.GetInt64(12)); [/b]
                            row[8] = new DateTime(dr.GetInt64(8)); 
                            row[9] = new DateTime(dr.GetInt64(9)); 
                            row[10] 

Open in new window

0
Why is this answer correct?

Revenue for Q2 is 300. Cost is 250. So profit is 300,000-250,000 = 50,000 but then Q1 and Q3 are also the same.

h3.png
0
No way this is that hard but I've been doing all this math stuff all afternoon and my brain is fried....

X is gas price
Increased by 15% so  X * .15
the price is now 3.91 ..I'm missing something

h1.png
0
For this one...
There are 15 even days. 15 odd days in a month.
On Even days, doctor works for 7 hours
On Odd days , doctor works or 7:30 hours

Nothing jumps out at me to see why 4 hours is correct... not sure how to go about this one...


t5.png
0
for this one... this is how I went about it

From 12 AM to 5 PM... we lose 5 mins each hour so that's 165 mins = 2.75 hours. But this doesn't get 3:35... I'm missing some calculation.



t4.png
0
The answer is 25% decrease. From the graph, I eliminated the 4 answers because the graph for "food and beverages" and "services" has decreased.

Why is it 25%? For example, food & Beverages went from 60 Million to 50 Million and Services went from 20 million to 10 million. I wanted to say... what percentage of 50 million is less than 60 million...

t1.png
0
Why is the answer to this is 100?

That's 500 mins of free call in the grid... it's not 500 per min. One year is 12 months.... hmmm... I don't know how 100 is correct.

t1.png
0

C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).